mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Change typeof narrowing to narrow selected union members (#25243)
* For typeof narrow all union members prior to filtering * Revise narrowTypeByTypeof to both narrow unions and applicable union members * Add repros from issue
This commit is contained in:
16
tests/cases/compiler/strictTypeofUnionNarrowing.ts
Normal file
16
tests/cases/compiler/strictTypeofUnionNarrowing.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// @strict: true
|
||||
function stringify1(anything: { toString(): string } | undefined): string {
|
||||
return typeof anything === "string" ? anything.toUpperCase() : "";
|
||||
}
|
||||
|
||||
function stringify2(anything: {} | undefined): string {
|
||||
return typeof anything === "string" ? anything.toUpperCase() : "";
|
||||
}
|
||||
|
||||
function stringify3(anything: unknown | undefined): string { // should simplify to just `unknown` which should narrow fine
|
||||
return typeof anything === "string" ? anything.toUpperCase() : "";
|
||||
}
|
||||
|
||||
function stringify4(anything: { toString?(): string } | undefined): string {
|
||||
return typeof anything === "string" ? anything.toUpperCase() : "";
|
||||
}
|
||||
Reference in New Issue
Block a user