Repository navigation
Error 2339 with nullish coalescing to empty objectΒ #51665
Copy link
Copy link
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisHelp WantedYou can do thisYou can do this
Milestone
Description
Activity
- addedBugA bug in TypeScriptA bug in TypeScriptHelp WantedYou can do thisYou can do this
on Dec 1, 2022 After replacing the
??operator with older-style code I still get an error (TS4.9.5):const ko_result = ko(); const assert_some_obj = ko_result === null ? {} : ko_result; // same for `ko_result || {}` const { oid, pid } = assert_some_obj; // Property 'pid' does not exist on type '{}'. ts(2339)
This is correct, isn't it?
With the same rewrite this also gives no error in the case of the
ok()function though. But I'd rather expect an error in both cases and ideally with the union type boiled down to the second union member:π Expected behavior
Error
Property does not exist on type '{}' (2339)in both examples.
PS:
const { pid } = {}; // Initializer provides no value for this binding element and the binding element has no default value. ts(2525) // Binding element 'pid' implicitly has an 'any' type. ts(7031)
So this does not look like fully sane code anyway.
Reacted by Jesse JafaNote that there is a pretty organic repro occurring with regexp parsing:
const re = /.*/; const str = "matched"; const result = re.exec(str); if (result != null) { const { namedGroup } = result.groups ?? {}; console.log(namedGroup.toLowerCase()); // runtime error! }
(for a more minimal repro)
// this issue is specifically triggered by index signatures declare const maybeIndexable: { [key: string]: string} | undefined const { anyThing } = maybeIndexable ?? {}; console.log(anyThing.toLowerCase()); // runtime error!
- addedDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysis
on Oct 16, 2025
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisHelp WantedYou can do thisYou can do this
Bug Report
π Search Terms
2339 Property does not exist on type empty object
π Version & Regression Information
Tested on 4.2.3 (version we use on our project) and 4.8.4 (latest available in playground)
β― Playground Link
Playground link with relevant code
π» Code
This is a simplified test case. I did encounter error while using @reach/router useMatch hook API
π Actual behavior
Error
Property does not exist on type '{ [param: string]: string; uri: string; path: string; } | {}' (2339)π Expected behavior
No error expected