mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-26 09:19:04 -05:00
Add test case for 'useUnknownInCatchVariables'.
This commit is contained in:
23
tests/cases/compiler/useUnknownInCatchVariables01.ts
Normal file
23
tests/cases/compiler/useUnknownInCatchVariables01.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// @useUnknownInCatchVariables: true
|
||||
|
||||
try {
|
||||
// ...
|
||||
}
|
||||
catch (e) {
|
||||
// error!
|
||||
void e.toUpperCase();
|
||||
void e++;
|
||||
void e();
|
||||
|
||||
if (typeof e === "string") {
|
||||
// works!
|
||||
// We've narrowed 'e' down to the type 'string'.
|
||||
console.log(e.toUpperCase());
|
||||
}
|
||||
if (e instanceof Error) {
|
||||
e.stack?.toUpperCase();
|
||||
}
|
||||
if (typeof e === "number") {
|
||||
e++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user