Skip to content

Error 2339 with nullish coalescing to empty objectΒ #51665

Open
@KuSh

Description

@KuSh

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

const ok = (): null | { [param: string]: string } => Math.random() > .5 ? null : {};
const ko = (): null | { uri: string; path: string; [param: string]: string } => Math.random() > .5 ? null : { uri: '', path: '' };

{
    // no errors
    const { oid, pid } = ok() ?? {};
}

{
    // error 2339 - Property does not exist on type '{ [param: string]: string; uri: string; path: string; } | {}'
    const { oid, pid } = ko() ?? {};
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions