-
Notifications
You must be signed in to change notification settings - Fork 12.8k
NonNullable
is not resolved for a mapped type in a contextual parameter type from instantiated type alias
#51331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The change between release-4.6 and main occurred at 51b346d. |
The core issue here is the normalization we perform on index types. Specifically, we generally normalize type Foo = { x: string } | undefined;
type Bar = { y: string };
type FooAndBar = Foo & Bar;
type Keys<T, U> = keyof (T & U); // Normalized into keyof T | keyof U
type K1 = keyof Foo; // never
type K2 = keyof Bar; // "y"
type K3 = Keys<Foo, Bar>; // "y"
type K4 = keyof (Foo & Bar); // "x" | "y" Above, We already have logic in place to defer types like |
I have similar issue in 5.4.x and 5.5.x type TypePropertyNames<T, U> = NonNullable<{[K in keyof T]: NonNullable<T[K]> extends U ? K : never}[keyof T]>;
interface Test {
field1?: boolean;
field2: boolean;
field3: string;
}
type TestFields = TypePropertyNames<Test, boolean>;
// should be 'field1' | 'field2'
// but now 'field1' | 'field2' | undefined
type TestFields2 = NonNullable<TypePropertyNames<Test, boolean>>; // this works correct Output"use strict"; Compiler Options{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"target": "ES2017",
"jsx": "react",
"module": "ESNext",
"moduleResolution": "node"
}
} Playground Link: Provided Is this the same bug? |
Bug Report
π Search Terms
NonNullable, Omit, mapped type, contextual type
π Version & Regression Information
β― Playground Link
Playground link with relevant code
Original repro case
π» Code
π Actual behavior
We can observe a type error in the
doesntWork
function and thekeyof
reporting incorrect result there for the given parameter type.π Expected behavior
There should be no error as the type for the
state
parameter in both functions is the same.cc @ahejlsberg
The text was updated successfully, but these errors were encountered: