Microsoft/TypeScript

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

Open

#35,738 opened on 2019年12月17日

GitHub で見る
 (1 comment) (0 reactions) (0 assignees)TypeScript (6,726 forks)batch import
Domain: Error MessagesEffort: ModerateExperience EnhancementHelp WantedSuggestion

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (平均マージ 6d 17h) (30d で 9 merged PRs)

説明

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?"

コントリビューターガイド