-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch typeof any could be checked for unreachable
- Loading branch information
1 parent
9ac7412
commit f3e4ba4
Showing
6 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/unreachableSwitchTypeofAny.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
tests/cases/compiler/unreachable.ts(12,5): error TS7027: Unreachable code detected. | ||
|
||
|
||
==== tests/cases/compiler/unreachable.ts (1 errors) ==== | ||
const unreachable = (x: any): number => { | ||
switch (typeof x) { | ||
case 'string': return 0 | ||
case 'number': return 0 | ||
case 'bigint': return 0 | ||
case 'boolean': return 0 | ||
case 'symbol': return 0 | ||
case 'undefined': return 0 | ||
case 'object': return 0 | ||
case 'function': return 0 | ||
} | ||
x; | ||
~~ | ||
!!! error TS7027: Unreachable code detected. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [unreachable.ts] | ||
const unreachable = (x: any): number => { | ||
switch (typeof x) { | ||
case 'string': return 0 | ||
case 'number': return 0 | ||
case 'bigint': return 0 | ||
case 'boolean': return 0 | ||
case 'symbol': return 0 | ||
case 'undefined': return 0 | ||
case 'object': return 0 | ||
case 'function': return 0 | ||
} | ||
x; | ||
} | ||
|
||
//// [unreachable.js] | ||
var unreachable = function (x) { | ||
switch (typeof x) { | ||
case 'string': return 0; | ||
case 'number': return 0; | ||
case 'bigint': return 0; | ||
case 'boolean': return 0; | ||
case 'symbol': return 0; | ||
case 'undefined': return 0; | ||
case 'object': return 0; | ||
case 'function': return 0; | ||
} | ||
x; | ||
}; |
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/unreachableSwitchTypeofAny.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
=== tests/cases/compiler/unreachable.ts === | ||
const unreachable = (x: any): number => { | ||
>unreachable : Symbol(unreachable, Decl(unreachable.ts, 0, 5)) | ||
>x : Symbol(x, Decl(unreachable.ts, 0, 21)) | ||
|
||
switch (typeof x) { | ||
>x : Symbol(x, Decl(unreachable.ts, 0, 21)) | ||
|
||
case 'string': return 0 | ||
case 'number': return 0 | ||
case 'bigint': return 0 | ||
case 'boolean': return 0 | ||
case 'symbol': return 0 | ||
case 'undefined': return 0 | ||
case 'object': return 0 | ||
case 'function': return 0 | ||
} | ||
x; | ||
>x : Symbol(x, Decl(unreachable.ts, 0, 21)) | ||
} |
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/unreachableSwitchTypeofAny.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
=== tests/cases/compiler/unreachable.ts === | ||
const unreachable = (x: any): number => { | ||
>unreachable : (x: any) => number | ||
>(x: any): number => { switch (typeof x) { case 'string': return 0 case 'number': return 0 case 'bigint': return 0 case 'boolean': return 0 case 'symbol': return 0 case 'undefined': return 0 case 'object': return 0 case 'function': return 0 } x;} : (x: any) => number | ||
>x : any | ||
|
||
switch (typeof x) { | ||
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>x : any | ||
|
||
case 'string': return 0 | ||
>'string' : "string" | ||
>0 : 0 | ||
|
||
case 'number': return 0 | ||
>'number' : "number" | ||
>0 : 0 | ||
|
||
case 'bigint': return 0 | ||
>'bigint' : "bigint" | ||
>0 : 0 | ||
|
||
case 'boolean': return 0 | ||
>'boolean' : "boolean" | ||
>0 : 0 | ||
|
||
case 'symbol': return 0 | ||
>'symbol' : "symbol" | ||
>0 : 0 | ||
|
||
case 'undefined': return 0 | ||
>'undefined' : "undefined" | ||
>0 : 0 | ||
|
||
case 'object': return 0 | ||
>'object' : "object" | ||
>0 : 0 | ||
|
||
case 'function': return 0 | ||
>'function' : "function" | ||
>0 : 0 | ||
} | ||
x; | ||
>x : any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @Filename: unreachable.ts | ||
// @outDir: out | ||
// @allowUnreachableCode: false | ||
const unreachable = (x: any): number => { | ||
switch (typeof x) { | ||
case 'string': return 0 | ||
case 'number': return 0 | ||
case 'bigint': return 0 | ||
case 'boolean': return 0 | ||
case 'symbol': return 0 | ||
case 'undefined': return 0 | ||
case 'object': return 0 | ||
case 'function': return 0 | ||
} | ||
x; | ||
} |