-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript 5.4: NonNullable
does not always exclude undefined
#56644
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
Bisects to #56515 |
The problem is that this PR implement this logic:
It got implemented here: But now... to do its thing it operates on the The constraint of this conditional type is just The problem is that A potential fix for this would be to include |
Oh, I should have read the latest comments below this PR. It seems that @ahejlsberg already commented on this particular issue here:
So it seems that the current conclusion is that fixing this would be too breaking and that the type in |
I also noticed a regression with the 5.3 -> 5.4 migration in this playground export type NonNullableKeys<T, U> = NonNullable<
{
[K in keyof T]: [U] extends [T[K]]
? T[K] extends U
? K
: never
: never;
}[keyof T]
>;
export type Foo = {
foo?: string;
};
type Hello = NonNullableKeys<Foo, string | undefined>
// ^?
// type Hello = "foo" in TS 5.3.3
// type Hello = "foo" | undefined in TS 5.4.2 |
If this is a regression that we don't want to fix (for technical reason), should the breaking change be mentioned in the release note? |
The thing that is weird is that if type Bar = NonNullableKeys<Foo, string | undefined>
// ^?
// type Bar = "foo" in TS 5.3.3
// type Bar = "foo" | undefined in TS 5.4.2
type Paz = NonNullable<Bar>
// ^?
// type Paz = "foo" in both |
This is the same issue - so I'd say that it works as intended as per @ahejlsberg's resolution.
This is because |
@Andarist It seems to me that this issue has been closed prematurely. The underlying issue is that there's an expectation that |
The current definition of You could try to spin up a new discussion thread about it but so far this new behavior has been classified as a design limitation more than once (IIRC) |
I get that this has been called a design limitation, and I'm all in favor of a performant type FilteredKeys<T> = {[K in keyof T]: SomePredicate<K, T[K]> extends true ? K : never}[keyof T]; When I see (with some surprise) that this type includes I can't imagine this is something a linter could detect? I just think there needs to be something to prevent this sort of frustration that I anticipate will recur pretty often. |
I dont disagree that this is a footgun - im not a fan of this. I dont call any shots here though. Thatβs why i've proposed creating a new discussion about it |
Closes: ngneat#119 Angular 18 requires TS 5.4+ which breaks the NonNullable type: microsoft/TypeScript#56644 This reintroduces issue ngneat#81. This commit replaces NonNullable with Exclude to allow correct typing of ExtractRefProp and fix the issue where opening dialogs containing undefined values throws TS2769 when trying to set the data property.
π Search Terms
NonNullable undefined
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?strict=false&strictPropertyInitialization=false&strictBindCallApply=false&noImplicitReturns=false&ts=5.4.0-dev.20231202#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgYQgFsiIkB1KTMMNAHgAU4BeOAbwF8A+dgKDkRIAbhADWwOvwHSBAaTihUSACYBnOADkyGgK4AbPZgBGeiVJkW+l69IDa85HHEBPCOjgMAugC4P9zwogSmpwABShAHRRmFAA5r6YSM62ngCULDwiCMrpAD5wOirA6MjAynAA-HDyvkjAQmgA3OY2cBy2Lm4eni0yXAA0LVyhvdLIIuIMUBBgGphEwL6ygzKpvgz+zRy8vMioGDh4APJgMAhkmHoAYoXYZ2RTM1bS6Lf3SI9gFaFrcFnKWx2ymA2EMUDw2DIqngAHcqDQ0L5CCQyJRqLQoHQTu9LjckHdzh9pmAuDs4ei0BFxmJgKEAESvfHvT501K8ckIqBU4Q00KFYElOo5IA
π» Code
π Actual behavior
No error
π Expected behavior
Argument of type 'undefined' is not assignable to parameter of type '"functionProp"'.(2345)
Additional information about the issue
Breaks
@types/enzyme
tests: https://github.com/DefinitelyTyped/DefinitelyTyped/actions/runs/7057196205/job/19245682552?pr=67570The text was updated successfully, but these errors were encountered: