Closed
Description
TypeScript Version: 3.3.0-dev.201xxxxx
Search Terms:
Domain: Conditional Types
extends null
Code
type CannotBeNull<T> = {
readonly [P in keyof T]: T[P] extends NonNullable<T[P]> ? true : false;
};
type DoesntCheckNull<T> = {
readonly [P in keyof T]: T[P] extends null ? false : true;
};
type MyData = {
name: string,
age: number,
hasChild: boolean,
childAge: null | number,
childName: null | string
};
type DataWhichArentNull = CannotBeNull<MyData>;
type DataAreAllTrue = DoesntCheckNull<MyData>;
Expected behavior:
The DoesntCheckNull<T>
should have the same result as DataWhichArentNull<T>
because it re-uses the logic in NonNullable<T>
i.e. DataWhichAreAllTrue
should look like:
{
name: true,
age: true,
hasChild: true,
childAge: false,
childName: false,
}
Actual behavior:
DataWhichAreAllTrue
actually looks like:
{
name: true,
age: true,
hasChild: true,
childAge: true,
childName: true,
}
Playground Link:
playground N.B. turn on --strictNullChecks
flag in Options
Related Issues:
Possibly related to 25413.
I thought it was related to 23843, but that was fixed in a PR that was merged 19 days ago, but I could reproduce this issue even when using typescript@next.