Accept new baselines

This commit is contained in:
Anders Hejlsberg 2016-09-24 15:59:06 -07:00
parent 9771f429ed
commit a8e004255e
3 changed files with 777 additions and 0 deletions

View File

@ -0,0 +1,174 @@
//// [literalTypeWidening.ts]
// Widening vs. non-widening literal types
function f1() {
const c1 = "hello"; // Widening type "hello"
let v1 = c1; // Type string
const c2 = c1; // Widening type "hello"
let v2 = c2; // Type string
const c3: "hello" = "hello"; // Type "hello"
let v3 = c3; // Type "hello"
const c4: "hello" = c1; // Type "hello"
let v4 = c4; // Type "hello"
}
function f2(cond: boolean) {
const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
const c2: "foo" | "bar" = c1; // "foo" | "bar"
const c3 = cond ? c1 : c2; // "foo" | "bar"
const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz"
let v1 = c1; // string
let v2 = c2; // "foo" | "bar"
let v3 = c3; // "foo" | "bar"
let v4 = c4; // string
let v5 = c5; // "foo" | "bar" | "baz"
}
function f3() {
const c1 = 123; // Widening type 123
let v1 = c1; // Type number
const c2 = c1; // Widening type 123
let v2 = c2; // Type number
const c3: 123 = 123; // Type 123
let v3 = c3; // Type 123
const c4: 123 = c1; // Type 123
let v4 = c4; // Type 123
}
function f4(cond: boolean) {
const c1 = cond ? 123 : 456; // widening 123 | widening 456
const c2: 123 | 456 = c1; // 123 | 456
const c3 = cond ? c1 : c2; // 123 | 456
const c4 = cond ? c3 : 789; // 123 | 456 | widening 789
const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789
let v1 = c1; // number
let v2 = c2; // 123 | 456
let v3 = c3; // 123 | 456
let v4 = c4; // number
let v5 = c5; // 123 | 456 | 789
}
function f5() {
const c1 = "foo";
let v1 = c1;
const c2: "foo" = "foo";
let v2 = c2;
const c3 = "foo" as "foo";
let v3 = c3;
const c4 = <"foo">"foo";
let v4 = c4;
}
// Repro from #10898
type FAILURE = "FAILURE";
const FAILURE = "FAILURE";
type Result<T> = T | FAILURE;
function doWork<T>(): Result<T> {
return FAILURE;
}
function isSuccess<T>(result: Result<T>): result is T {
return !isFailure(result);
}
function isFailure<T>(result: Result<T>): result is FAILURE {
return result === FAILURE;
}
function increment(x: number): number {
return x + 1;
}
let result = doWork<number>();
if (isSuccess(result)) {
increment(result);
}
// Repro from #10898
type TestEvent = "onmouseover" | "onmouseout";
function onMouseOver(): TestEvent { return "onmouseover"; }
let x = onMouseOver();
//// [literalTypeWidening.js]
// Widening vs. non-widening literal types
function f1() {
var c1 = "hello"; // Widening type "hello"
var v1 = c1; // Type string
var c2 = c1; // Widening type "hello"
var v2 = c2; // Type string
var c3 = "hello"; // Type "hello"
var v3 = c3; // Type "hello"
var c4 = c1; // Type "hello"
var v4 = c4; // Type "hello"
}
function f2(cond) {
var c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
var c2 = c1; // "foo" | "bar"
var c3 = cond ? c1 : c2; // "foo" | "bar"
var c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
var c5 = c4; // "foo" | "bar" | "baz"
var v1 = c1; // string
var v2 = c2; // "foo" | "bar"
var v3 = c3; // "foo" | "bar"
var v4 = c4; // string
var v5 = c5; // "foo" | "bar" | "baz"
}
function f3() {
var c1 = 123; // Widening type 123
var v1 = c1; // Type number
var c2 = c1; // Widening type 123
var v2 = c2; // Type number
var c3 = 123; // Type 123
var v3 = c3; // Type 123
var c4 = c1; // Type 123
var v4 = c4; // Type 123
}
function f4(cond) {
var c1 = cond ? 123 : 456; // widening 123 | widening 456
var c2 = c1; // 123 | 456
var c3 = cond ? c1 : c2; // 123 | 456
var c4 = cond ? c3 : 789; // 123 | 456 | widening 789
var c5 = c4; // 123 | 456 | 789
var v1 = c1; // number
var v2 = c2; // 123 | 456
var v3 = c3; // 123 | 456
var v4 = c4; // number
var v5 = c5; // 123 | 456 | 789
}
function f5() {
var c1 = "foo";
var v1 = c1;
var c2 = "foo";
var v2 = c2;
var c3 = "foo";
var v3 = c3;
var c4 = "foo";
var v4 = c4;
}
var FAILURE = "FAILURE";
function doWork() {
return FAILURE;
}
function isSuccess(result) {
return !isFailure(result);
}
function isFailure(result) {
return result === FAILURE;
}
function increment(x) {
return x + 1;
}
var result = doWork();
if (isSuccess(result)) {
increment(result);
}
function onMouseOver() { return "onmouseover"; }
var x = onMouseOver();

View File

@ -0,0 +1,285 @@
=== tests/cases/conformance/types/literal/literalTypeWidening.ts ===
// Widening vs. non-widening literal types
function f1() {
>f1 : Symbol(f1, Decl(literalTypeWidening.ts, 0, 0))
const c1 = "hello"; // Widening type "hello"
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
let v1 = c1; // Type string
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 4, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
const c2 = c1; // Widening type "hello"
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 5, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
let v2 = c2; // Type string
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 6, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 5, 9))
const c3: "hello" = "hello"; // Type "hello"
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 7, 9))
let v3 = c3; // Type "hello"
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 8, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 7, 9))
const c4: "hello" = c1; // Type "hello"
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 9, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9))
let v4 = c4; // Type "hello"
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 10, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 9, 9))
}
function f2(cond: boolean) {
>f2 : Symbol(f2, Decl(literalTypeWidening.ts, 11, 1))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
const c2: "foo" | "bar" = c1; // "foo" | "bar"
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
const c3 = cond ? c1 : c2; // "foo" | "bar"
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9))
const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9))
const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz"
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 18, 9))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9))
let v1 = c1; // string
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 19, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9))
let v2 = c2; // "foo" | "bar"
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 20, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9))
let v3 = c3; // "foo" | "bar"
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 21, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9))
let v4 = c4; // string
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 22, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9))
let v5 = c5; // "foo" | "bar" | "baz"
>v5 : Symbol(v5, Decl(literalTypeWidening.ts, 23, 7))
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 18, 9))
}
function f3() {
>f3 : Symbol(f3, Decl(literalTypeWidening.ts, 24, 1))
const c1 = 123; // Widening type 123
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
let v1 = c1; // Type number
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 28, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
const c2 = c1; // Widening type 123
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 29, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
let v2 = c2; // Type number
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 30, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 29, 9))
const c3: 123 = 123; // Type 123
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 31, 9))
let v3 = c3; // Type 123
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 32, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 31, 9))
const c4: 123 = c1; // Type 123
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 33, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9))
let v4 = c4; // Type 123
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 34, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 33, 9))
}
function f4(cond: boolean) {
>f4 : Symbol(f4, Decl(literalTypeWidening.ts, 35, 1))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
const c1 = cond ? 123 : 456; // widening 123 | widening 456
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
const c2: 123 | 456 = c1; // 123 | 456
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
const c3 = cond ? c1 : c2; // 123 | 456
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9))
const c4 = cond ? c3 : 789; // 123 | 456 | widening 789
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9))
>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9))
const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 42, 9))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9))
let v1 = c1; // number
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 43, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9))
let v2 = c2; // 123 | 456
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 44, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9))
let v3 = c3; // 123 | 456
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 45, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9))
let v4 = c4; // number
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 46, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9))
let v5 = c5; // 123 | 456 | 789
>v5 : Symbol(v5, Decl(literalTypeWidening.ts, 47, 7))
>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 42, 9))
}
function f5() {
>f5 : Symbol(f5, Decl(literalTypeWidening.ts, 48, 1))
const c1 = "foo";
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 51, 9))
let v1 = c1;
>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 52, 7))
>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 51, 9))
const c2: "foo" = "foo";
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 53, 9))
let v2 = c2;
>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 54, 7))
>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 53, 9))
const c3 = "foo" as "foo";
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 55, 9))
let v3 = c3;
>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 56, 7))
>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 55, 9))
const c4 = <"foo">"foo";
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 57, 9))
let v4 = c4;
>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 58, 7))
>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 57, 9))
}
// Repro from #10898
type FAILURE = "FAILURE";
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
const FAILURE = "FAILURE";
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
type Result<T> = T | FAILURE;
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12))
>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12))
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
function doWork<T>(): Result<T> {
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29))
>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16))
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16))
return FAILURE;
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
}
function isSuccess<T>(result: Result<T>): result is T {
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1))
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19))
return !isFailure(result);
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1))
>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22))
}
function isFailure<T>(result: Result<T>): result is FAILURE {
>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1))
>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26))
>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19))
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
return result === FAILURE;
>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22))
>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5))
}
function increment(x: number): number {
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1))
>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19))
return x + 1;
>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19))
}
let result = doWork<number>();
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29))
if (isSuccess(result)) {
>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1))
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
increment(result);
>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1))
>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3))
}
// Repro from #10898
type TestEvent = "onmouseover" | "onmouseout";
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1))
function onMouseOver(): TestEvent { return "onmouseover"; }
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46))
>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1))
let x = onMouseOver();
>x : Symbol(x, Decl(literalTypeWidening.ts, 96, 3))
>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46))

View File

@ -0,0 +1,318 @@
=== tests/cases/conformance/types/literal/literalTypeWidening.ts ===
// Widening vs. non-widening literal types
function f1() {
>f1 : () => void
const c1 = "hello"; // Widening type "hello"
>c1 : "hello"
>"hello" : "hello"
let v1 = c1; // Type string
>v1 : string
>c1 : "hello"
const c2 = c1; // Widening type "hello"
>c2 : "hello"
>c1 : "hello"
let v2 = c2; // Type string
>v2 : string
>c2 : "hello"
const c3: "hello" = "hello"; // Type "hello"
>c3 : "hello"
>"hello" : "hello"
let v3 = c3; // Type "hello"
>v3 : "hello"
>c3 : "hello"
const c4: "hello" = c1; // Type "hello"
>c4 : "hello"
>c1 : "hello"
let v4 = c4; // Type "hello"
>v4 : "hello"
>c4 : "hello"
}
function f2(cond: boolean) {
>f2 : (cond: boolean) => void
>cond : boolean
const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar"
>c1 : "foo" | "bar"
>cond ? "foo" : "bar" : "foo" | "bar"
>cond : boolean
>"foo" : "foo"
>"bar" : "bar"
const c2: "foo" | "bar" = c1; // "foo" | "bar"
>c2 : "foo" | "bar"
>c1 : "foo" | "bar"
const c3 = cond ? c1 : c2; // "foo" | "bar"
>c3 : "foo" | "bar"
>cond ? c1 : c2 : "foo" | "bar"
>cond : boolean
>c1 : "foo" | "bar"
>c2 : "foo" | "bar"
const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz"
>c4 : "foo" | "bar" | "baz"
>cond ? c3 : "baz" : "foo" | "bar" | "baz"
>cond : boolean
>c3 : "foo" | "bar"
>"baz" : "baz"
const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz"
>c5 : "foo" | "bar" | "baz"
>c4 : "foo" | "bar" | "baz"
let v1 = c1; // string
>v1 : string
>c1 : "foo" | "bar"
let v2 = c2; // "foo" | "bar"
>v2 : "foo" | "bar"
>c2 : "foo" | "bar"
let v3 = c3; // "foo" | "bar"
>v3 : "foo" | "bar"
>c3 : "foo" | "bar"
let v4 = c4; // string
>v4 : string
>c4 : "foo" | "bar" | "baz"
let v5 = c5; // "foo" | "bar" | "baz"
>v5 : "foo" | "bar" | "baz"
>c5 : "foo" | "bar" | "baz"
}
function f3() {
>f3 : () => void
const c1 = 123; // Widening type 123
>c1 : 123
>123 : 123
let v1 = c1; // Type number
>v1 : number
>c1 : 123
const c2 = c1; // Widening type 123
>c2 : 123
>c1 : 123
let v2 = c2; // Type number
>v2 : number
>c2 : 123
const c3: 123 = 123; // Type 123
>c3 : 123
>123 : 123
let v3 = c3; // Type 123
>v3 : 123
>c3 : 123
const c4: 123 = c1; // Type 123
>c4 : 123
>c1 : 123
let v4 = c4; // Type 123
>v4 : 123
>c4 : 123
}
function f4(cond: boolean) {
>f4 : (cond: boolean) => void
>cond : boolean
const c1 = cond ? 123 : 456; // widening 123 | widening 456
>c1 : 123 | 456
>cond ? 123 : 456 : 123 | 456
>cond : boolean
>123 : 123
>456 : 456
const c2: 123 | 456 = c1; // 123 | 456
>c2 : 123 | 456
>c1 : 123 | 456
const c3 = cond ? c1 : c2; // 123 | 456
>c3 : 123 | 456
>cond ? c1 : c2 : 123 | 456
>cond : boolean
>c1 : 123 | 456
>c2 : 123 | 456
const c4 = cond ? c3 : 789; // 123 | 456 | widening 789
>c4 : 123 | 456 | 789
>cond ? c3 : 789 : 123 | 456 | 789
>cond : boolean
>c3 : 123 | 456
>789 : 789
const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789
>c5 : 123 | 456 | 789
>c4 : 123 | 456 | 789
let v1 = c1; // number
>v1 : number
>c1 : 123 | 456
let v2 = c2; // 123 | 456
>v2 : 123 | 456
>c2 : 123 | 456
let v3 = c3; // 123 | 456
>v3 : 123 | 456
>c3 : 123 | 456
let v4 = c4; // number
>v4 : number
>c4 : 123 | 456 | 789
let v5 = c5; // 123 | 456 | 789
>v5 : 123 | 456 | 789
>c5 : 123 | 456 | 789
}
function f5() {
>f5 : () => void
const c1 = "foo";
>c1 : "foo"
>"foo" : "foo"
let v1 = c1;
>v1 : string
>c1 : "foo"
const c2: "foo" = "foo";
>c2 : "foo"
>"foo" : "foo"
let v2 = c2;
>v2 : "foo"
>c2 : "foo"
const c3 = "foo" as "foo";
>c3 : "foo"
>"foo" as "foo" : "foo"
>"foo" : "foo"
let v3 = c3;
>v3 : "foo"
>c3 : "foo"
const c4 = <"foo">"foo";
>c4 : "foo"
><"foo">"foo" : "foo"
>"foo" : "foo"
let v4 = c4;
>v4 : "foo"
>c4 : "foo"
}
// Repro from #10898
type FAILURE = "FAILURE";
>FAILURE : "FAILURE"
const FAILURE = "FAILURE";
>FAILURE : "FAILURE"
>"FAILURE" : "FAILURE"
type Result<T> = T | FAILURE;
>Result : Result<T>
>T : T
>T : T
>FAILURE : "FAILURE"
function doWork<T>(): Result<T> {
>doWork : <T>() => Result<T>
>T : T
>Result : Result<T>
>T : T
return FAILURE;
>FAILURE : "FAILURE"
}
function isSuccess<T>(result: Result<T>): result is T {
>isSuccess : <T>(result: Result<T>) => result is T
>T : T
>result : Result<T>
>Result : Result<T>
>T : T
>result : any
>T : T
return !isFailure(result);
>!isFailure(result) : boolean
>isFailure(result) : boolean
>isFailure : <T>(result: Result<T>) => result is "FAILURE"
>result : Result<T>
}
function isFailure<T>(result: Result<T>): result is FAILURE {
>isFailure : <T>(result: Result<T>) => result is "FAILURE"
>T : T
>result : Result<T>
>Result : Result<T>
>T : T
>result : any
>FAILURE : "FAILURE"
return result === FAILURE;
>result === FAILURE : boolean
>result : Result<T>
>FAILURE : "FAILURE"
}
function increment(x: number): number {
>increment : (x: number) => number
>x : number
return x + 1;
>x + 1 : number
>x : number
>1 : 1
}
let result = doWork<number>();
>result : Result<number>
>doWork<number>() : Result<number>
>doWork : <T>() => Result<T>
if (isSuccess(result)) {
>isSuccess(result) : boolean
>isSuccess : <T>(result: Result<T>) => result is T
>result : Result<number>
increment(result);
>increment(result) : number
>increment : (x: number) => number
>result : number
}
// Repro from #10898
type TestEvent = "onmouseover" | "onmouseout";
>TestEvent : TestEvent
function onMouseOver(): TestEvent { return "onmouseover"; }
>onMouseOver : () => TestEvent
>TestEvent : TestEvent
>"onmouseover" : "onmouseover"
let x = onMouseOver();
>x : TestEvent
>onMouseOver() : TestEvent
>onMouseOver : () => TestEvent