-
Notifications
You must be signed in to change notification settings - Fork 12.8k
null extends object inconsistent between ts and d.ts #33174
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
I can not reproduce this behavior with TypeScript 3.5.3 or 3.6.2. It makes no difference whether it's in a Can you make sure that |
The behaviour as described by @MartinJohns is correct. Toggling |
I could only repro this at first, but it turned out that my tsconfig with strictNullChecks on only included my .ts file. It didn't include my d.ts file, which caused the type to be different. Can you check to see if that's what is happening? Once I got both files covered by the same tsconfig, they started behaving the same. |
In the TS file, export type SchrodingersCat = null extends object ? 'alive' : 'dead';
In a DTS file which has a matching TS file, export type SchrodingersCat = null extends object ? 'alive' : 'dead';
In a DTS file which has no matching TS file, Creating an empty file named export type SchrodingersCat = null extends object ? 'alive' : 'dead';
{
"dependencies": {
"typescript": "3.6.3"
}
}
Setting {
"compilerOptions": {
"strictNullChecks": true
}
} |
I'm pretty sure that's because when you don't explicitly list files in your tsconfig, and you have box.ts and box.d.ts, only box.ts is part of the compilation. @sheetalkamat can you confirm? |
@sandersn yes.
|
um, shouldn’t it be dead everywhere because null doesn’t extend object? |
Despite my love for cats, I agree logically this one should be However, most of the ecosystem is non-strict. By this I mean all type definition files published to npm. This means it could be a massive breaking change. Making the cat always This could also affect the decision to eventually enable |
@ljharb @remcohaszing I checked this again and the difference in .d.ts files is also whether strictNullChecks is true or false, not whether it's in a .d.ts file or not. I'm going to close this bug. |
@sandersn ok, but when strictNullChecks is on, |
Yep, it's 100% |
TypeScript Version: 3.5.3
Search Terms: null extends object
Code
Expected behavior:
SchrodingersCat
is either'dead'
or'alive'
.Actual behavior:
If the code is in a file named
box.ts
,SchrodingersCat
is'dead'
. If the code is in a file namedbox.d.ts
,SchrodingersCat
is'alive'
.Playground Link: N/A
Related Issues: N/A
The text was updated successfully, but these errors were encountered: