-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed as not planned
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
🔎 Search Terms
"Inference trims types", "inference excludes fields"
🕗 Version & Regression Information
- This is not a crash
- This changed between versions _4.9 and ___5.0
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
type Foo<T> = { name: "foo" } & T;
type Bar<T> = { value: T };
type Tidied<T> = T extends Bar<infer V> ? Tidied_Foo<T> : T;
type Tidied_Foo<T> = T extends Foo<infer V> ? T : T;
function foo<T>(cb: Tidied<T>) {
return cb;
}
const result1 = foo({ name: "foo", message: "Hey!" } as Foo<{ message: string }>);
result1.name; // Error: Property 'name' does not exist on type '{ message: string; }'
const result2 = foo({ name: "foo", message: "Hey!" });
result2.name; // No error🙁 Actual behavior
packages/server/src/test.ts:13:9 - error TS2339: Property 'name' does not exist on type '{ message: string; }'.
13 result1.name; // ...
~~~~
Found 1 error in packages/server/src/test.ts:13
🙂 Expected behavior
no type error
Additional information about the issue
I was working on my project Cuple. I found a weird bug. I spent my day to provide a small minimal example. I have a type Tidied which is used to make a developer friendly type from the complex built response types. It worked well for some cases but it doesn't work for the case that I provided. The original version makes more sense.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug