Skip to content

Commit

Permalink
Accepted baselines.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser committed Oct 9, 2020
1 parent 89a44a0 commit 87b36c9
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"useUnknownInCatchVariables": true
}
}
35 changes: 35 additions & 0 deletions tests/baselines/reference/useUnknownInCatchVariables01.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
tests/cases/compiler/useUnknownInCatchVariables01.ts(6,12): error TS2339: Property 'toUpperCase' does not exist on type 'unknown'.
tests/cases/compiler/useUnknownInCatchVariables01.ts(7,10): error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
tests/cases/compiler/useUnknownInCatchVariables01.ts(8,10): error TS2349: This expression is not callable.
Type '{}' has no call signatures.


==== tests/cases/compiler/useUnknownInCatchVariables01.ts (3 errors) ====
try {
// ...
}
catch (e) {
// error!
void e.toUpperCase();
~~~~~~~~~~~
!!! error TS2339: Property 'toUpperCase' does not exist on type 'unknown'.
void e++;
~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type.
void e();
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type '{}' has no call signatures.

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++;
}
}
45 changes: 45 additions & 0 deletions tests/baselines/reference/useUnknownInCatchVariables01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// [useUnknownInCatchVariables01.ts]
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++;
}
}

//// [useUnknownInCatchVariables01.js]
var _a;
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) {
(_a = e.stack) === null || _a === void 0 ? void 0 : _a.toUpperCase();
}
if (typeof e === "number") {
e++;
}
}
48 changes: 48 additions & 0 deletions tests/baselines/reference/useUnknownInCatchVariables01.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
=== tests/cases/compiler/useUnknownInCatchVariables01.ts ===
try {
// ...
}
catch (e) {
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))

// error!
void e.toUpperCase();
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))

void e++;
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))

void e();
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))

if (typeof e === "string") {
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))

// works!
// We've narrowed 'e' down to the type 'string'.
console.log(e.toUpperCase());
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>e.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
if (e instanceof Error) {
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

e.stack?.toUpperCase();
>e.stack?.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>e.stack : Symbol(Error.stack, Decl(lib.es5.d.ts, --, --))
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))
>stack : Symbol(Error.stack, Decl(lib.es5.d.ts, --, --))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
if (typeof e === "number") {
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))

e++;
>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7))
}
}
67 changes: 67 additions & 0 deletions tests/baselines/reference/useUnknownInCatchVariables01.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
=== tests/cases/compiler/useUnknownInCatchVariables01.ts ===
try {
// ...
}
catch (e) {
>e : unknown

// error!
void e.toUpperCase();
>void e.toUpperCase() : undefined
>e.toUpperCase() : any
>e.toUpperCase : any
>e : unknown
>toUpperCase : any

void e++;
>void e++ : undefined
>e++ : number
>e : unknown

void e();
>void e() : undefined
>e() : any
>e : unknown

if (typeof e === "string") {
>typeof e === "string" : boolean
>typeof e : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>e : unknown
>"string" : "string"

// works!
// We've narrowed 'e' down to the type 'string'.
console.log(e.toUpperCase());
>console.log(e.toUpperCase()) : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>e.toUpperCase() : string
>e.toUpperCase : () => string
>e : string
>toUpperCase : () => string
}
if (e instanceof Error) {
>e instanceof Error : boolean
>e : unknown
>Error : ErrorConstructor

e.stack?.toUpperCase();
>e.stack?.toUpperCase() : string
>e.stack?.toUpperCase : () => string
>e.stack : string
>e : Error
>stack : string
>toUpperCase : () => string
}
if (typeof e === "number") {
>typeof e === "number" : boolean
>typeof e : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>e : unknown
>"number" : "number"

e++;
>e++ : number
>e : number
}
}

0 comments on commit 87b36c9

Please sign in to comment.