Microsoft/TypeScript
Voir sur GitHubSurprising excess property check with recursive generic constraint
Open
#55 644 ouverte le 6 sept. 2023
Domain: check: Excess Property CheckingHelp WantedPossible Improvement
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
Description
🔎 Search Terms
excess property check recursive generic contraint type variable inference
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type StateSchema = {
states?: Record<string, StateSchema>;
};
declare function createMachine<TConfig extends StateSchema>(
config: TConfig,
): TConfig;
createMachine({
entry: [{ type: "foo" }],
states: {
a: {
entry: [{ type: "bar" }],
},
},
});
🙁 Actual behavior
At the nested entry property the error is raised:
Object literal may only specify known properties, and 'entry' does not exist in type 'StateSchema'.(2353)
but it isn't raised at the entry property at the root of this object.
🙂 Expected behavior
I'd expect no excess property error to be raised with a recursive constraint like this.
Additional information about the issue
This particular case is somewhat easily fixable by adding [k: string]: unknown to StateSchema. I still find the reported behavior to be a problem though.