Microsoft/TypeScript

"Did you mean parent object or child property?" in error messsages

Open

#35,738 创建于 2019年12月17日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
Domain: Error MessagesEffort: ModerateExperience EnhancementHelp WantedSuggestion

仓库指标

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

描述

Discussed with @RyanCavanaugh from his personal dev experience.

It's common to get an error message when accidentally using an inner property of an object. Similarly, we might forget to actually fetch an inner property of an object.

// @strict: true

interface Person {
  residence: House;
}

interface House {
  isHouseOfPain: boolean;
}

declare let home: House;
declare let person: Person;

   home = person.residence.isHouseOfPain;
// ~~~~
// error: Type 'boolean' is not assignable to type 'House'.

   home = person;
// ~~~~
// error: Property 'isHouseOfPain' is missing in type 'Person' but required in type 'House'.
//   related: 'isHouseOfPain' is declared here.

It'd be nice if we could hint to the user "hey, you might have dotted too far into this object" or "hey, did you mean to grab the residence property?"

贡献者指南