Microsoft/TypeScript

Error 2339 with nullish coalescing to empty object

Open

#51,665 创建于 2022年11月28日

在 GitHub 查看
 (3 评论) (2 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: check: Control FlowHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

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

贡献者指南