/arkcompiler/ets_runtime/test/typeinfer/automatedcases/ |
D | stringLiteralTypeAssertion01.ts | 21 type S = "a" | "b"; 22 type T = S[] | S; 24 let s: S; 25 AssertType(s, "S"); 35 s = <S>t; 36 AssertType(s = <S>t, "S"); 37 AssertType(s, "S"); 38 AssertType(<S>t, "S"); 41 s = t as S; 42 AssertType(s = t as S, "S"); [all …]
|
D | contextuallyTypingOrOperator.ts | 21 let v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; 25 AssertType({ a: s => s.length } || { a: s => 1 }, "{ a: (string) => number; }"); 26 AssertType({ a: s => s.length }, "{ a: (string) => number; }"); 28 AssertType(s => s.length, "(string) => number"); 29 AssertType(s, "string"); 30 AssertType(s.length, "number"); 31 AssertType({ a: s => 1 }, "{ a: (string) => number; }"); 33 AssertType(s => 1, "(string) => number"); 34 AssertType(s, "string"); 37 let v2 = (s: string) => s.length || function (s) { s.length }; [all …]
|
D | genericFunctionParameters.ts | 21 declare function f1<T>(cb: <S>(x: S) => T): T; 22 declare function f2<T>(cb: <S extends number>(x: S) => T): T; 23 declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T; 30 AssertType(f1, "<T>(<S>(S) => T) => T"); 32 AssertType(x => x, "<S>(S) => S"); 34 AssertType(x, "S"); 36 AssertType(x, "S"); 42 AssertType(f2, "<T>(<S extends number>(S) => T) => T"); 43 AssertType(x => x, "<S extends number>(S) => S"); 44 AssertType(x, "S"); [all …]
|
D | uniqueSymbols.ts | 361 declare const s: unique symbol; constant 362 AssertType(s, "unique symbol"); 364 declare namespace N { const s: unique symbol; } constant 365 declare const o: { [s]: "a", [N.s]: "b" }; 366 AssertType(o, "{ [s]: "a"; [N.s]: "b"; }"); 367 AssertType([s], "string"); 368 AssertType(s, "unique symbol"); 369 AssertType([N.s], "string"); 370 AssertType(N.s, "unique symbol"); 373 declare function g(x: typeof s): void; [all …]
|
D | uniqueSymbolsDeclarations.ts | 354 declare const s: unique symbol; constant 355 AssertType(s, "unique symbol"); 357 declare namespace N { const s: unique symbol; } constant 358 declare const o: { [s]: "a", [N.s]: "b" }; 359 AssertType(o, "{ [s]: "a"; [N.s]: "b"; }"); 360 AssertType([s], "string"); 361 AssertType(s, "unique symbol"); 362 AssertType([N.s], "string"); 363 AssertType(N.s, "unique symbol"); 366 declare function g(x: typeof s): void; [all …]
|
D | contextuallyTypingOrOperator2.ts | 21 let v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; 25 AssertType({ a: s => s.length } || { a: s => 1 }, "{ a: (string) => number; }"); 26 AssertType({ a: s => s.length }, "{ a: (string) => number; }"); 28 AssertType(s => s.length, "(string) => number"); 29 AssertType(s, "string"); 30 AssertType(s.length, "number"); 31 AssertType({ a: s => 1 }, "{ a: (string) => number; }"); 33 AssertType(s => 1, "(string) => number"); 34 AssertType(s, "string"); 37 let v2 = (s: string) => s.length || function (s) { s.aaa }; [all …]
|
D | typeGuardNarrowsIndexedAccessOfKnownProperty1.ts | 44 function area(s: Shape): number { 45 switch(s['dash-ok']) { 46 AssertType(s['dash-ok'], "union"); 47 AssertType(s, "Shape"); 52 AssertType(s['square-size'] * s['square-size'], "number"); 53 AssertType(s['square-size'], "number"); 54 AssertType(s, "Square"); 56 AssertType(s['square-size'], "number"); 57 AssertType(s, "Square"); 59 return s['square-size'] * s['square-size']; [all …]
|
D | symbolType11.ts | 21 let s = Symbol.for("logical"); 22 AssertType(s, "symbol"); 27 s && s; 28 AssertType(s && s, "symbol"); 29 AssertType(s, "symbol"); 30 AssertType(s, "symbol"); 32 s && []; 33 AssertType(s && [], "undefined[]"); 34 AssertType(s, "symbol"); 37 0 && s; [all …]
|
D | uniqueSymbolsDeclarationsErrors.ts | 21 declare const s: unique symbol; 22 AssertType(s, "unique symbol"); 29 AssertType(obj, "{ method1(typeof s): typeof s; method2(I["readonlyType"]): I["readonlyType"]; }"); 30 …of s): typeof s { return p; }, method2(p: I["readonlyType"]): I["readonlyType"] { … 32 method1(p: typeof s): typeof s { 33 AssertType(method1, "(typeof s) => typeof s"); 35 AssertType(s, "unique symbol"); 36 AssertType(s, "unique symbol"); 53 AssertType(class { method1(p: typeof s): typeof s { return p; } method2(p: I["reado… 55 method1(p: typeof s): typeof s { [all …]
|
D | assignmentCompatWithGenericCallSignatures3.ts | 23 interface I<T, S> { 24 <U>(f: (x: T) => (y: S) => U): U 27 let g: <T>(x: T) => <S>(y: S) => I<T, S> 28 AssertType(g, "<T>(T) => <S>(S) => I<T, S>"); 30 AssertType(y, "S"); 32 let h: <T>(x: T) => <S>(y: S) => { <U>(f: (x: T) => (y: S) => U): U 33 AssertType(h, "<T>(T) => <S>(S) => <U>((T) => (S) => U) => U"); 37 AssertType(y, "S"); 39 AssertType(f, "(T) => (S) => U"); 43 AssertType(y, "S"); [all …]
|
D | literalTypes3.ts | 21 function f1(s: string) { 22 if (s === "foo") { 23 AssertType(s === "foo", "boolean"); 24 AssertType(s, "string"); 27 s; // "foo" 28 AssertType(s, "string"); 30 if (s === "foo" || s === "bar") { 31 AssertType(s === "foo" || s === "bar", "boolean"); 32 AssertType(s === "foo", "boolean"); 33 AssertType(s, "string"); [all …]
|
D | promiseChaining.ts | 23 then<S>(cb: (x: T) => S): Chain<S> { 25 AssertType(result, "S"); 26 AssertType(cb(this.value), "S"); 27 AssertType(cb, "(T) => S"); 32 …let z = this.then(x => result)/*S*/.then(x => "abc")/*string*/.then(x => x.length)/*number*/; // N… 34 AssertType(this.then(x => result)/*S*/.then(x => "abc")/*string*/.then(x => x.length), "Chain<numbe… 35 AssertType(this.then(x => result)/*S*/.then(x => "abc")/*string*/.then, "<S>((string) => S) => Chai… 36 AssertType(this.then(x => result)/*S*/.then(x => "abc"), "Chain<string>"); 37 AssertType(this.then(x => result)/*S*/.then, "<S>((S) => S) => Chain<S>"); 38 AssertType(this.then(x => result), "Chain<S>"); [all …]
|
D | mappedTypeContextualTypesApplied.ts | 21 type TakeString = (s: string) => any; 35 mapped1({foo: s => 42}); 36 AssertType(mapped1({foo: s => 42}), "void"); 38 AssertType({foo: s => 42}, "{ foo: (string) => number; }"); 40 AssertType(s => 42, "(string) => number"); 41 AssertType(s, "string"); 44 mapped2({foo: s => 42}); 45 AssertType(mapped2({foo: s => 42}), "void"); 47 AssertType({foo: s => 42}, "{ foo: (string) => number; }"); 49 AssertType(s => 42, "(string) => number"); [all …]
|
D | computedPropertyNames4_ES5.ts | 21 let s: string; 22 AssertType(s, "string"); 32 AssertType({ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0,… 34 [s]: 0, 35 AssertType([s], "number"); 36 AssertType(s, "string"); 44 [s + s]: 1, 45 AssertType([s + s], "number"); 46 AssertType(s + s, "string"); 47 AssertType(s, "string"); [all …]
|
D | computedPropertyNames4_ES6.ts | 21 let s: string; 22 AssertType(s, "string"); 32 AssertType({ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0,… 34 [s]: 0, 35 AssertType([s], "number"); 36 AssertType(s, "string"); 44 [s + s]: 1, 45 AssertType([s + s], "number"); 46 AssertType(s + s, "string"); 47 AssertType(s, "string"); [all …]
|
D | contextualSignatureInstantiation2.ts | 22 let dot: <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T) => (_: U) => S; 23 AssertType(dot, "<T, S>((T) => S) => <U>((U) => T) => (U) => S"); 24 AssertType(f, "(T) => S"); 30 dot = <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x)); 31 …rtType(dot = <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x)), "<T, S>(… 32 AssertType(dot, "<T, S>((T) => S) => <U>((U) => T) => (U) => S"); 33 AssertType(<T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x)), "<T, S>((T)… 34 AssertType(f, "(T) => S"); 36 AssertType(<U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x)), "<U>((U) => T) => (U) => S"); 40 AssertType((x) => f(g(x)), "(U) => S"); [all …]
|
D | privateNameInLhsReceiverExpression.ts | 24 obj[(new class { #x = 1; readonly s = "prop"; }).s].#y = 1; 25 AssertType(obj[(new class { #x = 1; readonly s = "prop"; }).s].#y = 1, "int"); 26 AssertType(obj[(new class { #x = 1; readonly s = "prop"; }).s].#y, "number"); 27 AssertType(obj[(new class { #x = 1; readonly s = "prop"; }).s], "Test"); 29 AssertType((new class { #x = 1; readonly s = "prop"; }).s, "string"); 30 AssertType((new class { #x = 1; readonly s = "prop"; }), "(Anonymous class)"); 31 AssertType(new class { #x = 1; readonly s = "prop"; }, "(Anonymous class)"); 32 AssertType(class { #x = 1; readonly s = "prop"; }, "typeof (Anonymous class)"); 35 AssertType(s, "string"); 39 obj[(new class { #x = 1; readonly s = "prop"; }).s].#y += 1; [all …]
|
D | bestChoiceType.ts | 23 (''.match(/ /) || []).map(s => s.toLowerCase()); 24 AssertType((''.match(/ /) || []).map(s => s.toLowerCase()), "any[]"); 26 AssertType(s => s.toLowerCase(), "(any) => any"); 27 AssertType(s, "any"); 28 AssertType(s.toLowerCase(), "any"); 29 AssertType(s.toLowerCase, "any"); 47 let z = y.map(s => s.toLowerCase()); 49 AssertType(y.map(s => s.toLowerCase()), "any[]"); 51 AssertType(s => s.toLowerCase(), "(any) => any"); 52 AssertType(s, "any"); [all …]
|
D | inferentialTypingWithFunctionTypeZip.ts | 21 let pair: <T, S>(x: T) => (y: S) => { x: T; y: S; 22 AssertType(pair, "<T, S>(T) => (S) => { x: T; y: S; }"); 26 AssertType(y, "S"); 30 AssertType(y, "S"); 33 let zipWith: <T, S, U>(a: T[], b: S[], f: (x: T) => (y: S) => U) => U[]; 34 AssertType(zipWith, "<T, S, U>(T[], S[], (T) => (S) => U) => U[]"); 36 AssertType(b, "S[]"); 37 AssertType(f, "(T) => (S) => U"); 39 AssertType(y, "S"); 44 AssertType(zipWith, "<T, S, U>(T[], S[], (T) => (S) => U) => U[]"); [all …]
|
D | subtypingWithOptionalProperties.ts | 23 // returns { s?: number; } 25 let b: { s?: number } = a; 26 AssertType(b, "{ s?: number; }"); 27 AssertType(s, "number"); 30 AssertType(b, "{ s?: number; }"); 34 let r = f({ s: new Object() }); // ok 35 AssertType(r, "{ s?: number; }"); 36 AssertType(f({ s: new Object() }), "{ s?: number; }"); 37 AssertType(f, "<T>(T) => { s?: number; }"); 38 AssertType({ s: new Object() }, "{ s: Object; }"); [all …]
|
D | computedPropertyNames10_ES6.ts | 21 let s: string; 22 AssertType(s, "string"); 32 AssertType({ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]… 34 [s]() { }, 35 AssertType([s], "() => void"); 36 AssertType(s, "string"); 42 [s + s]() { }, 43 AssertType([s + s], "() => void"); 44 AssertType(s + s, "string"); 45 AssertType(s, "string"); [all …]
|
D | conditionalTypeBasedContextualTypeReturnTypeWidening.ts | 21 declare function useState1<S>(initialState: (S extends (() => any) ? never : S) | (() => S)): S; //… 22 declare function useState2<S>(initialState: (S extends ((...args: any[]) => any) ? never : S) | (()… 27 AssertType(useState1, "<S>(union) => S"); 35 AssertType(useState2, "<S>(union) => S"); 40 declare function useState3<S, T extends S>(initialState: (T extends (() => any) ? never : T) | (() … 41 declare function useState4<S, T extends S>(initialState: (T extends ((...args: any[]) => any) ? nev… 46 AssertType(useState1, "<S>(union) => S"); 54 AssertType(useState2, "<S>(union) => S");
|
D | computedPropertyNames10_ES5.ts | 21 let s: string; 22 AssertType(s, "string"); 32 AssertType({ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]… 34 [s]() { }, 35 AssertType([s], "() => void"); 36 AssertType(s, "string"); 42 [s + s]() { }, 43 AssertType([s + s], "() => void"); 44 AssertType(s + s, "string"); 45 AssertType(s, "string"); [all …]
|
D | targetTypingOnFunctions.ts | 21 let fu: (s: string) => string = function (s) { 23 AssertType(s, "string"); 24 AssertType(function (s) { return s.toLowerCase() }, "(string) => string"); 25 AssertType(s, "string"); 26 AssertType(s.toLowerCase(), "string"); 27 AssertType(s.toLowerCase, "() => string"); 28 return s.toLowerCase() }; 30 let zu = fu = function (s) { 32 AssertType(fu = function (s) { return s.toLowerCase() }, "(string) => string"); 34 AssertType(function (s) { return s.toLowerCase() }, "(string) => string"); [all …]
|
D | computedPropertyNames11_ES6.ts | 21 let s: string; 22 AssertType(s, "string"); 32 AssertType({ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set … 34 get [s]() { 35 AssertType([s], "number"); 36 AssertType(s, "string"); 45 get [s + s]() { 46 AssertType([s + s], "number"); 47 AssertType(s + s, "string"); 48 AssertType(s, "string"); [all …]
|