file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
crates/swc_ecma_parser/tests/tsc/spreadUnion3.ts
TypeScript
// @strictNullChecks: true function f(x: { y: string } | undefined): { y: string } { return { y: 123, ...x } // y: string | number } f(undefined) function g(t?: { a: number } | null): void { let b = { ...t }; let c: number = b.a; // might not have 'a' } g() g(undefined) g(null) // spreading nothing but null and undefined is not allowed declare const nullAndUndefinedUnion: null | undefined; var x = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion }; var y = { ...nullAndUndefinedUnion };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/spreadUnion4.ts
TypeScript
declare const a: { x: () => void } declare const b: { x?: () => void } const c = { ...a, ...b };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticAndNonStaticPropertiesSameName.ts
TypeScript
class C { x: number; static x: number; f() { } static f() { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticAutoAccessors.ts
TypeScript
// @target: es2022,es2017 // @noTypesAndSymbols: true // https://github.com/microsoft/TypeScript/issues/53752 class A { // uses class reference static accessor x = 1; // uses 'this' accessor y = 2; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticAutoAccessorsWithDecorators.ts
TypeScript
// @target: es2022,es2017 // @noTypesAndSymbols: true // https://github.com/microsoft/TypeScript/issues/53752 class A { // uses class reference @((t, c) => {}) static accessor x = 1; // uses 'this' @((t, c) => {}) accessor y = 2; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticFactory1.ts
TypeScript
class Base { foo() { return 1; } static create() { return new this(); } } class Derived extends Base { foo() { return 2; } } var d = Derived.create(); d.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticIndexSignature1.ts
TypeScript
class C { static [s: string]: number; static [s: number]: 42 } C["foo"] = 1 C.bar = 2; const foo = C["foo"] C[42] = 42 C[2] = 2; const bar = C[42]
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticIndexSignature2.ts
TypeScript
class C { static readonly [s: string]: number; static readonly [s: number]: 42 } C["foo"] = 1 C.bar = 2; const foo = C["foo"] C[42] = 42 C[2] = 2; const bar = C[42]
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticIndexSignature3.ts
TypeScript
// @strict: true class B { static readonly [s: string]: number; static readonly [s: number]: 42 | 233 } class D extends B { static readonly [s: string]: number } class ED extends D { static readonly [s: string]: boolean static readonly [s: number]: 1 } class DD extends D { static readonly [s: string]: 421 } const a = B["f"]; const b = B[42]; const c = D["f"] const d = D[42] const e = ED["f"] const f = ED[42] const g = DD["f"] const h = DD[42]
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticIndexSignature6.ts
TypeScript
// @strict: true function foo () { return class<T> { static [s: string]: number static [s: number]: 42 foo(v: T) { return v } } } const C = foo() C.a; C.a = 1; C[2]; C[2] = 42; const c = new C<number>(); c.foo(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticIndexSignature7.ts
TypeScript
// @strict: true class X { static [index: string]: string; static x = 12; // Should error, incompatible with index signature } class Y { static [index: string]: string; static foo() {} // should error, incompatible with index signature }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticIndexers.ts
TypeScript
// static indexers not allowed class C { static [x: string]: string; } class D { static [x: number]: string; } class E<T> { static [x: string]: T; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticMemberAssignsToConstructorFunctionMembers.ts
TypeScript
class C { static foo() { C.foo = () => { } } static bar(x: number): number { C.bar = () => { } // error C.bar = (x) => x; // ok C.bar = (x: number) => 1; // ok return 1; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticMemberInitialization.ts
TypeScript
class C { static x = 1; } var c = new C(); var r = C.x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticMembersUsingClassTypeParameter.ts
TypeScript
// BUG 745747 class C<T> { static x: T; static f(x: T) {} } class C2<T, U> { static x: U; static f(x: U) { } } class C3<T extends Date> { static x: T; static f(x: T) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticPropertyAndFunctionWithSameName.ts
TypeScript
class C { static f: number; f: number; } class D { static f: number; f() { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticPropertyNameConflictsInAmbientContext.ts
TypeScript
//@Filename: decl.d.ts // name declare class StaticName { static name: number; // ok name: string; // ok } declare class StaticNameFn { static name(): string; // ok name(): string; // ok } // length declare class StaticLength { static length: number; // ok length: string; // ok } declare class StaticLengthFn { static length(): number; // ok length(): number; // ok } // prototype declare class StaticPrototype { static prototype: number; // ok prototype: string; // ok } declare class StaticPrototypeFn { static prototype: any; // ok prototype(): any; // ok } // caller declare class StaticCaller { static caller: number; // ok caller: string; // ok } declare class StaticCallerFn { static caller(): any; // ok caller(): any; // ok } // arguments declare class StaticArguments { static arguments: number; // ok arguments: string; // ok } declare class StaticArgumentsFn { static arguments(): any; // ok arguments(): any; // ok }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/staticPropertyNotInClassType.ts
TypeScript
module NonGeneric { class C { fn() { return this; } static get x() { return 1; } static set x(v) { } constructor(public a: number, private b: number) { } static foo: string; // not reflected in class type } module C { export var bar = ''; // not reflected in class type } var c = new C(1, 2); var r = c.fn(); var r4 = c.foo; // error var r5 = c.bar; // error var r6 = c.x; // error } module Generic { class C<T, U> { fn() { return this; } static get x() { return 1; } static set x(v) { } constructor(public a: T, private b: U) { } static foo: T; // not reflected in class type } module C { export var bar = ''; // not reflected in class type } var c = new C(1, ''); var r = c.fn(); var r4 = c.foo; // error var r5 = c.bar; // error var r6 = c.x; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/strictBindCallApply1.ts
TypeScript
// @strict: true declare function foo(a: number, b: string): string; declare function overloaded(s: string): number; declare function overloaded(n: number): string; declare function generic<T>(x: T): T; let f00 = foo.bind(undefined); let f01 = foo.bind(undefined, 10); let f02 = foo.bind(undefined, 10, "hello"); let f03 = foo.bind(undefined, 10, 20); // Error let f04 = overloaded.bind(undefined); // typeof overloaded let f05 = generic.bind(undefined); // typeof generic let c00 = foo.call(undefined, 10, "hello"); let c01 = foo.call(undefined, 10); // Error let c02 = foo.call(undefined, 10, 20); // Error let c03 = foo.call(undefined, 10, "hello", 30); // Error let a00 = foo.apply(undefined, [10, "hello"]); let a01 = foo.apply(undefined, [10]); // Error let a02 = foo.apply(undefined, [10, 20]); // Error let a03 = foo.apply(undefined, [10, "hello", 30]); // Error class C { constructor(a: number, b: string) {} foo(this: this, a: number, b: string): string { return "" } overloaded(s: string): number; overloaded(n: number): string; overloaded(x: any): any { return <any>undefined } generic<T>(x: T): T { return x } } declare let c: C; declare let obj: {}; let f10 = c.foo.bind(c); let f11 = c.foo.bind(c, 10); let f12 = c.foo.bind(c, 10, "hello"); let f13 = c.foo.bind(c, 10, 20); // Error let f14 = c.foo.bind(undefined); // Error let f15 = c.overloaded.bind(c); // typeof C.prototype.overloaded let f16 = c.generic.bind(c); // typeof C.prototype.generic let c10 = c.foo.call(c, 10, "hello"); let c11 = c.foo.call(c, 10); // Error let c12 = c.foo.call(c, 10, 20); // Error let c13 = c.foo.call(c, 10, "hello", 30); // Error let c14 = c.foo.call(undefined, 10, "hello"); // Error let a10 = c.foo.apply(c, [10, "hello"]); let a11 = c.foo.apply(c, [10]); // Error let a12 = c.foo.apply(c, [10, 20]); // Error let a13 = c.foo.apply(c, [10, "hello", 30]); // Error let a14 = c.foo.apply(undefined, [10, "hello"]); // Error let f20 = C.bind(undefined); let f21 = C.bind(undefined, 10); let f22 = C.bind(undefined, 10, "hello"); let f23 = C.bind(undefined, 10, 20); // Error C.call(c, 10, "hello"); C.call(c, 10); // Error C.call(c, 10, 20); // Error C.call(c, 10, "hello", 30); // Error C.apply(c, [10, "hello"]); C.apply(c, [10]); // Error C.apply(c, [10, 20]); // Error C.apply(c, [10, "hello", 30]); // Error function bar<T extends unknown[]>(callback: (this: 1, ...args: T) => void) { callback.bind(1); callback.bind(2); // Error } function baz<T extends 1 | 2>(callback: (this: 1, ...args: T extends 1 ? [unknown] : [unknown, unknown]) => void) { callback.bind(1); callback.bind(2); // Error } // Repro from #32964 class Foo<T extends unknown[]> { constructor() { this.fn.bind(this); } fn(...args: T): void {} } class Bar<T extends 1 | 2> { constructor() { this.fn.bind(this); } fn(...args: T extends 1 ? [unknown] : [unknown, unknown]) {} }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/strictBindCallApply2.ts
TypeScript
// @strictFunctionTypes: false // @strictBindCallApply: true // Repro from #32964 interface Foo { blub: string }; function fn(this: Foo) {} type Test = ThisParameterType<typeof fn>; const fb = fn.bind({ blub: "blub" });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/strictNullChecksNoWidening.ts
TypeScript
// @strictNullChecks: true var a1 = null; var a2 = undefined; var a3 = void 0; var b1 = []; var b2 = [,]; var b3 = [undefined]; var b4 = [[], []]; var b5 = [[], [,]]; declare function f<T>(x: T): T; var c1 = f(null); var c2 = f(undefined); var c3 = f([]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/strictPropertyInitialization.ts
TypeScript
// @strict: true // @target: es2015 // @declaration: true // Properties with non-undefined types require initialization class C1 { a: number; // Error b: number | undefined; c: number | null; // Error d?: number; #f: number; //Error #g: number | undefined; #h: number | null; //Error #i?: number; } // No strict initialization checks in ambient contexts declare class C2 { a: number; b: number | undefined; c: number | null; d?: number; #f: number; #g: number | undefined; #h: number | null; #i?: number; } // No strict initialization checks for static members class C3 { static a: number; static b: number | undefined; static c: number | null; static d?: number; } // Initializer satisfies strict initialization check class C4 { a = 0; b: number = 0; c: string = "abc"; #d = 0 #e: number = 0 #f: string= "abc" } // Assignment in constructor satisfies strict initialization check class C5 { a: number; #b: number; constructor() { this.a = 0; this.#b = 0; } } // All code paths must contain assignment class C6 { a: number; // Error #b: number constructor(cond: boolean) { if (cond) { return; } this.a = 0; this.#b = 0; } } class C7 { a: number; #b: number; constructor(cond: boolean) { if (cond) { this.a = 1; this.#b = 1; return; } this.a = 0; this.#b = 1; } } // Properties with string literal names aren't checked class C8 { a: number; // Error "b": number; 0: number; } // No strict initialization checks for abstract members abstract class C9 { abstract a: number; abstract b: number | undefined; abstract c: number | null; abstract d?: number; } // Properties with non-undefined types must be assigned before they can be accessed // within their constructor class C10 { a: number; b: number; c?: number; #d: number; constructor() { let x = this.a; // Error this.a = this.b; // Error this.b = this.#d //Error this.b = x; this.#d = x; let y = this.c; } } // Property is considered initialized by type any even though value could be undefined declare function someValue(): any; class C11 { a: number; #b: number; constructor() { this.a = someValue(); this.#b = someValue(); } } const a = 'a'; const b = Symbol(); class C12 { [a]: number; [b]: number; ['c']: number; constructor() { this[a] = 1; this[b] = 1; this['c'] = 1; } } enum E { A = "A", B = "B" } class C13 { [E.A]: number; constructor() { this[E.A] = 1; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/strictTupleLength.ts
TypeScript
var t0: []; var t1: [number]; var t2: [number, number]; var arr: number[]; var len0: 0 = t0.length; var len1: 1 = t1.length; var len2: 2 = t2.length; var lena: number = arr.length; var t1 = t2; // error var t2 = t1; // error type A<T extends any[]> = T['length']; var b: A<[boolean]>; var c: 1 = b; t1 = arr; // error with or without strict arr = t1; // ok with or without strict
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringEnumInElementAccess01.ts
TypeScript
// @noImplicitAny: true enum E { A = "a", B = "b", C = "c", } interface Item { a: string; b: number; c: boolean; } declare const item: Item; declare const e: E; const snb: string | number | boolean = item[e];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringEnumLiteralTypes1.ts
TypeScript
const enum Choice { Unknown = "", Yes = "yes", No = "no" }; type YesNo = Choice.Yes | Choice.No; type NoYes = Choice.No | Choice.Yes; type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; function f1() { var a: YesNo; var a: NoYes; var a: Choice.Yes | Choice.No; var a: Choice.No | Choice.Yes; } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { b = a; c = a; c = b; } function f3(a: Choice.Yes, b: YesNo) { var x = a + b; var y = a == b; var y = a != b; var y = a === b; var y = a !== b; var y = a > b; var y = a < b; var y = a >= b; var y = a <= b; var y = !b; } declare function g(x: Choice.Yes): string; declare function g(x: Choice.No): boolean; declare function g(x: Choice): number; function f5(a: YesNo, b: UnknownYesNo, c: Choice) { var z1 = g(Choice.Yes); var z2 = g(Choice.No); var z3 = g(a); var z4 = g(b); var z5 = g(c); } function assertNever(x: never): never { throw new Error("Unexpected value"); } function f10(x: YesNo) { switch (x) { case Choice.Yes: return "true"; case Choice.No: return "false"; } } function f11(x: YesNo) { switch (x) { case Choice.Yes: return "true"; case Choice.No: return "false"; } return assertNever(x); } function f12(x: UnknownYesNo) { if (x) { x; } else { x; } } function f13(x: UnknownYesNo) { if (x === Choice.Yes) { x; } else { x; } } type Item = { kind: Choice.Yes, a: string } | { kind: Choice.No, b: string }; function f20(x: Item) { switch (x.kind) { case Choice.Yes: return x.a; case Choice.No: return x.b; } } function f21(x: Item) { switch (x.kind) { case Choice.Yes: return x.a; case Choice.No: return x.b; } return assertNever(x); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringEnumLiteralTypes2.ts
TypeScript
// @strictNullChecks: true const enum Choice { Unknown = "", Yes = "yes", No = "no" }; type YesNo = Choice.Yes | Choice.No; type NoYes = Choice.No | Choice.Yes; type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; function f1() { var a: YesNo; var a: NoYes; var a: Choice.Yes | Choice.No; var a: Choice.No | Choice.Yes; } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { b = a; c = a; c = b; } function f3(a: Choice.Yes, b: YesNo) { var x = a + b; var y = a == b; var y = a != b; var y = a === b; var y = a !== b; var y = a > b; var y = a < b; var y = a >= b; var y = a <= b; var y = !b; } declare function g(x: Choice.Yes): string; declare function g(x: Choice.No): boolean; declare function g(x: Choice): number; function f5(a: YesNo, b: UnknownYesNo, c: Choice) { var z1 = g(Choice.Yes); var z2 = g(Choice.No); var z3 = g(a); var z4 = g(b); var z5 = g(c); } function assertNever(x: never): never { throw new Error("Unexpected value"); } function f10(x: YesNo) { switch (x) { case Choice.Yes: return "true"; case Choice.No: return "false"; } } function f11(x: YesNo) { switch (x) { case Choice.Yes: return "true"; case Choice.No: return "false"; } return assertNever(x); } function f12(x: UnknownYesNo) { if (x) { x; } else { x; } } function f13(x: UnknownYesNo) { if (x === Choice.Yes) { x; } else { x; } } type Item = { kind: Choice.Yes, a: string } | { kind: Choice.No, b: string }; function f20(x: Item) { switch (x.kind) { case Choice.Yes: return x.a; case Choice.No: return x.b; } } function f21(x: Item) { switch (x.kind) { case Choice.Yes: return x.a; case Choice.No: return x.b; } return assertNever(x); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringEnumLiteralTypes3.ts
TypeScript
const enum Choice { Unknown = "", Yes = "yes", No = "no" }; type Yes = Choice.Yes; type YesNo = Choice.Yes | Choice.No; type NoYes = Choice.No | Choice.Yes; type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { a = a; a = b; a = c; a = d; } function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { b = a; b = b; b = c; b = d; } function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { c = a; c = b; c = c; c = d; } function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { d = a; d = b; d = c; d = d; } function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { a = Choice.Unknown; a = Choice.Yes; a = Choice.No; b = Choice.Unknown; b = Choice.Yes; b = Choice.No; c = Choice.Unknown; c = Choice.Yes; c = Choice.No; d = Choice.Unknown; d = Choice.Yes; d = Choice.No; } function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { a === Choice.Unknown; a === Choice.Yes; a === Choice.No; b === Choice.Unknown; b === Choice.Yes; b === Choice.No; c === Choice.Unknown; c === Choice.Yes; c === Choice.No; d === Choice.Unknown; d === Choice.Yes; d === Choice.No; } function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { a === a; a === b; a === c; a === d; b === a; b === b; b === c; b === d; c === a; c === b; c === c; c === d; d === a; d === b; d === c; d === d; } function f10(x: Yes): Yes { switch (x) { case Choice.Unknown: return x; case Choice.Yes: return x; case Choice.No: return x; } return x; } function f11(x: YesNo): YesNo { switch (x) { case Choice.Unknown: return x; case Choice.Yes: return x; case Choice.No: return x; } return x; } function f12(x: UnknownYesNo): UnknownYesNo { switch (x) { case Choice.Unknown: return x; case Choice.Yes: return x; case Choice.No: return x; } return x; } function f13(x: Choice): Choice { switch (x) { case Choice.Unknown: return x; case Choice.Yes: return x; case Choice.No: return x; } return x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringIndexerConstrainsPropertyDeclarations.ts
TypeScript
// String indexer types constrain the types of named properties in their containing type interface MyString extends String { foo: number; } class C { [x: string]: string; constructor() { } // ok a: string; // ok b: number; // error c: () => {} // error "d": string; // ok "e": number; // error 1.0: string; // ok 2.0: number; // error "3.0": string; // ok "4.0": number; // error f: MyString; // error get X() { // ok return ''; } set X(v) { } // ok foo() { // error return ''; } static sa: number; // ok static sb: string; // ok static foo() { } // ok static get X() { // ok return 1; } } interface I { [x: string]: string; a: string; // ok b: number; // error c: () => {} // error "d": string; // ok "e": number; // error 1.0: string; // ok 2.0: number; // error (): string; // ok (x): number // ok foo(): string; // error "3.0": string; // ok "4.0": number; // error f: MyString; // error } var a: { [x: string]: string; a: string; // ok b: number; // error c: () => {} // error "d": string; // ok "e": number; // error 1.0: string; // ok 2.0: number; // error (): string; // ok (x): number // ok foo(): string; // error "3.0": string; // ok "4.0": number; // error f: MyString; // error } // error var b: { [x: string]: string; } = { a: '', b: 1, c: () => { }, "d": '', "e": 1, 1.0: '', 2.0: 1, "3.0": '', "4.0": 1, f: <MyString>null, get X() { return ''; }, set X(v) { }, foo() { return ''; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringIndexerConstrainsPropertyDeclarations2.ts
TypeScript
// String indexer providing a constraint of a user defined type class A { foo(): string { return ''; } } class B extends A { bar(): string { return ''; } } class Foo { [x: string]: A; a: A; // ok b: B; // ok c: number; // error d: string; // error } interface Foo2 { [x: string]: A; a: A; // ok b: B; // ok c: number; // error d: string; // error } var a: { [x: string]: A; a: A; // ok b: B; // ok c: number; // error d: string; // error }; // error var b: { [x: string]: A } = { a: A, b: B }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringIndexingResults.ts
TypeScript
class C { [x: string]: string; y = ''; } var c: C; var r1 = c['y']; var r2 = c['a']; var r3 = c[1]; interface I { [x: string]: string; y: string; } var i: I var r4 = i['y']; var r5 = i['a']; var r6 = i[1]; var a: { [x: string]: string; y: string; } var r7 = a['y']; var r8 = a['a']; var r9 = a[1]; var b: { [x: string]: string } = { y: '' } var r10 = b['y']; var r11 = b['a']; var r12 = b[1];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralCheckedInIf01.ts
TypeScript
 type S = "a" | "b"; type T = S[] | S; function f(foo: T) { if (foo === "a") { return foo; } else if (foo === "b") { return foo; } else { return (foo as S[])[0]; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralCheckedInIf02.ts
TypeScript
 type S = "a" | "b"; type T = S[] | S; function isS(t: T): t is S { return t === "a" || t === "b"; } function f(foo: T) { if (isS(foo)) { return foo; } else { return foo[0]; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralMatchedInSwitch01.ts
TypeScript
 type S = "a" | "b"; type T = S[] | S; var foo: T; switch (foo) { case "a": case "b": break; default: foo = (foo as S[])[0]; break; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralType.ts
TypeScript
var x: 'hi'; function f(x: 'hi'); function f(x: string); function f(x: any) { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypeAssertion01.ts
TypeScript
 type S = "a" | "b"; type T = S[] | S; var s: S; var t: T; var str: string; //////////////// s = <S>t; s = t as S; s = <S>str; s = str as S; //////////////// t = <T>s; t = s as T; t = <T>str; t = str as T; //////////////// str = <string>s; str = s as string; str = <string>t; str = t as string;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypeIsSubtypeOfString.ts
TypeScript
// string literal types are subtypes of string, any // ok function f1(x: 'a'); function f1(x: string); function f1(x: string) { } // ok function f2(x: 'a'); function f2(x: any); function f2(x: any) { } // errors function f3(x: 'a'); function f3(x: Object); function f3(x: any) { } function f4(x: 'a'); function f4(x: {}); function f4(x: any) { } function f5(x: 'a'); function f5(x: number); function f5(x: any) { } function f6(x: 'a'); function f6(x: boolean); function f6(x: any) { } function f7(x: 'a'); function f7(x: Date); function f7(x: any) { } function f8(x: 'a'); function f8(x: RegExp); function f8(x: any) { } function f9(x: 'a'); function f9(x: () => {}); function f9(x: any) { } class C implements String { toString(): string { return null; } charAt(pos: number): string { return null; } charCodeAt(index: number): number { return null; } concat(...strings: string[]): string { return null; } indexOf(searchString: string, position?: number): number { return null; } lastIndexOf(searchString: string, position?: number): number { return null; } localeCompare(that: string): number { return null; } match(regexp: any): RegExpMatchArray { return null; } replace(searchValue: any, replaceValue: any): string { return null; } search(regexp: any): number { return null; } slice(start?: number, end?: number): string { return null; } split(separator: any, limit?: number): string[] { return null; } substring(start: number, end?: number): string { return null; } toLowerCase(): string { return null; } toLocaleLowerCase(): string { return null; } toUpperCase(): string { return null; } toLocaleUpperCase(): string { return null; } trim(): string { return null; } length: number; substr(from: number, length?: number): string { return null; } valueOf(): string { return null; } [index: number]: string; } // BUG 831846 function f10(x: 'a'); function f10(x: C); function f10(x: any) { } interface I extends String { foo: string; } // BUG 831846 function f11(x: 'a'); function f11(x: I); function f11(x: any) { } function f12<T>(x: 'a'); function f12<T>(x: T); function f12<T>(x: any) { } function f13<T extends String>(x: 'a'); function f13<T extends String>(x: T); function f13<T extends String>(x: any) { } enum E { A } function f14(x: 'a'); function f14(x: E); function f14(x: any) { } function f15<T, U extends T>(x: 'a'); function f15<T, U extends T>(x: U); function f15<T, U extends T>(x: any) { } function f16<T extends String, U extends T>(x: 'a'); function f16<T extends String, U extends T>(x: U); function f16<T extends String, U extends T>(x: any) { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAndLogicalOrExpressions01.ts
TypeScript
// @declaration: true declare function myRandBool(): boolean; let a: "foo" = "foo"; let b = a || "foo"; let c: "foo" = b; let d = b || "bar"; let e: "foo" | "bar" = d;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAndParenthesizedExpressions01.ts
TypeScript
// @declaration: true declare function myRandBool(): boolean; let a: "foo" = ("foo"); let b: "foo" | "bar" = ("foo"); let c: "foo" = (myRandBool ? "foo" : ("foo")); let d: "foo" | "bar" = (myRandBool ? "foo" : ("bar"));
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAndTuples01.ts
TypeScript
// @declaration: true // Should all be strings. let [hello, brave, newish, world] = ["Hello", "Brave", "New", "World"]; type RexOrRaptor = "t-rex" | "raptor" let [im, a, dinosaur]: ["I'm", "a", RexOrRaptor] = ['I\'m', 'a', 't-rex']; rawr(dinosaur); function rawr(dino: RexOrRaptor) { if (dino === "t-rex") { return "ROAAAAR!"; } if (dino === "raptor") { return "yip yip!"; } throw "Unexpected " + dino; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAsTags01.ts
TypeScript
// @declaration: true type Kind = "A" | "B" interface Entity { kind: Kind; } interface A extends Entity { kind: "A"; a: number; } interface B extends Entity { kind: "B"; b: string; } function hasKind(entity: Entity, kind: "A"): entity is A; function hasKind(entity: Entity, kind: "B"): entity is B; function hasKind(entity: Entity, kind: Kind): entity is Entity; function hasKind(entity: Entity, kind: Kind): boolean { return entity.kind === kind; } let x: A = { kind: "A", a: 100, } if (hasKind(x, "A")) { let a = x; } else { let b = x; } if (!hasKind(x, "B")) { let c = x; } else { let d = x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAsTags02.ts
TypeScript
// @declaration: true type Kind = "A" | "B" interface Entity { kind: Kind; } interface A extends Entity { kind: "A"; a: number; } interface B extends Entity { kind: "B"; b: string; } function hasKind(entity: Entity, kind: "A"): entity is A; function hasKind(entity: Entity, kind: "B"): entity is B; function hasKind(entity: Entity, kind: Kind): entity is (A | B) { return entity.kind === kind; } let x: A = { kind: "A", a: 100, } if (hasKind(x, "A")) { let a = x; } else { let b = x; } if (!hasKind(x, "B")) { let c = x; } else { let d = x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAsTags03.ts
TypeScript
// @declaration: true type Kind = "A" | "B" interface Entity { kind: Kind; } interface A extends Entity { kind: "A"; a: number; } interface B extends Entity { kind: "B"; b: string; } // Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid // interpreting respective overloads as "specialized" signatures. // That way, we can avoid the need to look for a compatible overload // signature and simply check compatibility with the implementation. function hasKind(entity: Entity, kind: "A" | "A"): entity is A; function hasKind(entity: Entity, kind: "B" | "B"): entity is B; function hasKind(entity: Entity, kind: Kind): entity is Entity { return entity.kind === kind; } let x: A = { kind: "A", a: 100, } if (hasKind(x, "A")) { let a = x; } else { let b = x; } if (!hasKind(x, "B")) { let c = x; } else { let d = x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAsTypeParameterConstraint01.ts
TypeScript
// @declaration: true function foo<T extends "foo">(f: (x: T) => T) { return f; } function bar<T extends "foo" | "bar">(f: (x: T) => T) { return f; } let f = foo(x => x); let fResult = f("foo"); let g = foo((x => x)); let gResult = g("foo"); let h = bar(x => x); let hResult = h("foo"); hResult = h("bar");
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesAsTypeParameterConstraint02.ts
TypeScript
// @declaration: true function foo<T extends "foo">(f: (x: T) => T) { return f; } let f = foo((y: "foo" | "bar") => y === "foo" ? y : "foo"); let fResult = f("foo");
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesInImplementationSignatures.ts
TypeScript
// String literal types are only valid in overload signatures function foo(x: 'hi') { } var f = function foo(x: 'hi') { } var f2 = (x: 'hi', y: 'hi') => { } class C { foo(x: 'hi') { } } interface I { (x: 'hi'); foo(x: 'hi', y: 'hi'); } var a: { (x: 'hi'); foo(x: 'hi'); } var b = { foo(x: 'hi') { }, a: function foo(x: 'hi', y: 'hi') { }, b: (x: 'hi') => { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesInImplementationSignatures2.ts
TypeScript
// String literal types are only valid in overload signatures function foo(x: any); function foo(x: 'hi') { } class C { foo(x: string); foo(x: 'hi') { } } interface I { (x: 'a'); (x: 'hi'); foo(x: 'a', y: 'a'); foo(x: 'hi', y: 'hi'); } var a: { (x: 'hi'); (x: 'a'); foo(x: 'hi'); foo(x: 'a'); } var b = { foo(x: 'hi') { }, foo(x: 'a') { }, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesInUnionTypes01.ts
TypeScript
// @declaration: true type T = "foo" | "bar" | "baz"; var x: "foo" | "bar" | "baz" = undefined; var y: T = undefined; if (x === "foo") { let a = x; } else if (x !== "bar") { let b = x || y; } else { let c = x; let d = y; let e: (typeof x) | (typeof y) = c || d; } x = y; y = x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesInUnionTypes02.ts
TypeScript
// @declaration: true type T = string | "foo" | "bar" | "baz"; var x: "foo" | "bar" | "baz" | string = undefined; var y: T = undefined; if (x === "foo") { let a = x; } else if (x !== "bar") { let b = x || y; } else { let c = x; let d = y; let e: (typeof x) | (typeof y) = c || d; } x = y; y = x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesInUnionTypes03.ts
TypeScript
// @declaration: true type T = number | "foo" | "bar"; var x: "foo" | "bar" | number; var y: T = undefined; if (x === "foo") { let a = x; } else if (x !== "bar") { let b = x || y; } else { let c = x; let d = y; let e: (typeof x) | (typeof y) = c || d; } x = y; y = x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesInUnionTypes04.ts
TypeScript
// @declaration: true type T = "" | "foo"; let x: T = undefined; let y: T = undefined; if (x === "") { let a = x; } if (x !== "") { let b = x; } if (x == "") { let c = x; } if (x != "") { let d = x; } if (x) { let e = x; } if (!x) { let f = x; } if (!!x) { let g = x; } if (!!!x) { let h = x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloadAssignability01.ts
TypeScript
// @declaration: true function f(x: "foo"): number; function f(x: string): number { return 0; } function g(x: "bar"): number; function g(x: string): number { return 0; } let a = f; let b = g; a = b; b = a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloadAssignability02.ts
TypeScript
// @declaration: true function f(x: "foo"): number; function f(x: "foo"): number { return 0; } function g(x: "bar"): number; function g(x: "bar"): number { return 0; } let a = f; let b = g; a = b; b = a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloadAssignability03.ts
TypeScript
// @declaration: true function f(x: "foo"): number; function f(x: string): number { return 0; } function g(x: "foo"): number; function g(x: string): number { return 0; } let a = f; let b = g; a = b; b = a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloadAssignability04.ts
TypeScript
// @declaration: true function f(x: "foo"): number; function f(x: "foo"): number { return 0; } function g(x: "foo"): number; function g(x: "foo"): number { return 0; } let a = f; let b = g; a = b; b = a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloadAssignability05.ts
TypeScript
// @declaration: true function f(x: "foo"): number; function f(x: string): number; function f(x: string): number { return 0; } function g(x: "foo"): number; function g(x: string): number { return 0; } let a = f; let b = g; a = b; b = a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloads01.ts
TypeScript
// @declaration: true type PrimitiveName = 'string' | 'number' | 'boolean'; function getFalsyPrimitive(x: "string"): string; function getFalsyPrimitive(x: "number"): number; function getFalsyPrimitive(x: "boolean"): boolean; function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; function getFalsyPrimitive(x: "number" | "string"): number | string; function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { if (x === "string") { return ""; } if (x === "number") { return 0; } if (x === "boolean") { return false; } // Should be unreachable. throw "Invalid value"; } namespace Consts1 { const EMPTY_STRING = getFalsyPrimitive("string"); const ZERO = getFalsyPrimitive('number'); const FALSE = getFalsyPrimitive("boolean"); } const string: "string" = "string" const number: "number" = "number" const boolean: "boolean" = "boolean" const stringOrNumber = string || number; const stringOrBoolean = string || boolean; const booleanOrNumber = number || boolean; const stringOrBooleanOrNumber = stringOrBoolean || number; namespace Consts2 { const EMPTY_STRING = getFalsyPrimitive(string); const ZERO = getFalsyPrimitive(number); const FALSE = getFalsyPrimitive(boolean); const a = getFalsyPrimitive(stringOrNumber); const b = getFalsyPrimitive(stringOrBoolean); const c = getFalsyPrimitive(booleanOrNumber); const d = getFalsyPrimitive(stringOrBooleanOrNumber); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloads02.ts
TypeScript
// @declaration: true function getFalsyPrimitive(x: "string"): string; function getFalsyPrimitive(x: "number"): number; function getFalsyPrimitive(x: "boolean"): boolean; function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; function getFalsyPrimitive(x: "number" | "string"): number | string; function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; function getFalsyPrimitive(x: string): string | number | boolean { if (x === "string") { return ""; } if (x === "number") { return 0; } if (x === "boolean") { return false; } // Should be unreachable. throw "Invalid value"; } namespace Consts1 { const EMPTY_STRING = getFalsyPrimitive("string"); const ZERO = getFalsyPrimitive('number'); const FALSE = getFalsyPrimitive("boolean"); } const string = "string" const number = "number" const boolean = "boolean" const stringOrNumber = string || number; const stringOrBoolean = string || boolean; const booleanOrNumber = number || boolean; const stringOrBooleanOrNumber = stringOrBoolean || number; namespace Consts2 { const EMPTY_STRING = getFalsyPrimitive(string); const ZERO = getFalsyPrimitive(number); const FALSE = getFalsyPrimitive(boolean); const a = getFalsyPrimitive(stringOrNumber); const b = getFalsyPrimitive(stringOrBoolean); const c = getFalsyPrimitive(booleanOrNumber); const d = getFalsyPrimitive(stringOrBooleanOrNumber); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloads03.ts
TypeScript
// @declaration: true interface Base { x: string; y: number; } interface HelloOrWorld extends Base { p1: boolean; } interface JustHello extends Base { p2: boolean; } interface JustWorld extends Base { p3: boolean; } let hello: "hello"; let world: "world"; let helloOrWorld: "hello" | "world"; function f(p: "hello"): JustHello; function f(p: "hello" | "world"): HelloOrWorld; function f(p: "world"): JustWorld; function f(p: string): Base; function f(...args: any[]): any { return undefined; } let fResult1 = f(hello); let fResult2 = f(world); let fResult3 = f(helloOrWorld); function g(p: string): Base; function g(p: "hello"): JustHello; function g(p: "hello" | "world"): HelloOrWorld; function g(p: "world"): JustWorld; function g(...args: any[]): any { return undefined; } let gResult1 = g(hello); let gResult2 = g(world); let gResult3 = g(helloOrWorld);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloads04.ts
TypeScript
// @declaration: true declare function f(x: (p: "foo" | "bar") => "foo"); f(y => { const z = y = "foo"; return z; })
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesOverloads05.ts
TypeScript
// @declaration: true interface Animal { animal: {} }; interface Dog extends Animal { dog: {} } interface Cat extends Animal { cat: {} } interface Moose extends Animal { moose: {} } function doThing(x: "dog"): Dog; function doThing(x: "cat"): Cat; function doThing(x: string): Animal; function doThing(x: string, y?: string): Moose { return undefined; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesTypePredicates01.ts
TypeScript
// @declaration: true type Kind = "A" | "B" function kindIs(kind: Kind, is: "A"): kind is "A"; function kindIs(kind: Kind, is: "B"): kind is "B"; function kindIs(kind: Kind, is: Kind): boolean { return kind === is; } var x: Kind = undefined; if (kindIs(x, "A")) { let a = x; } else { let b = x; } if (!kindIs(x, "B")) { let c = x; } else { let d = x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesWithTemplateStrings01.ts
TypeScript
// @declaration: true let ABC: "ABC" = `ABC`; let DE_NEWLINE_F: "DE\nF" = `DE F`; let G_QUOTE_HI: 'G"HI'; let JK_BACKTICK_L: "JK`L" = `JK\`L`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesWithTemplateStrings02.ts
TypeScript
// @declaration: true let abc: "AB\r\nC" = `AB C`; let de_NEWLINE_f: "DE\nF" = `DE${"\n"}F`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesWithVariousOperators01.ts
TypeScript
// @declaration: true let abc: "ABC" = "ABC"; let xyz: "XYZ" = "XYZ"; let abcOrXyz: "ABC" | "XYZ" = abc || xyz; let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100; let a = "" + abc; let b = abc + ""; let c = 10 + abc; let d = abc + 10; let e = xyz + abc; let f = abc + xyz; let g = true + abc; let h = abc + true; let i = abc + abcOrXyz + xyz; let j = abcOrXyz + abcOrXyz; let k = +abcOrXyz; let l = -abcOrXyz; let m = abcOrXyzOrNumber + ""; let n = "" + abcOrXyzOrNumber; let o = abcOrXyzOrNumber + abcOrXyz; let p = abcOrXyz + abcOrXyzOrNumber; let q = !abcOrXyzOrNumber; let r = ~abcOrXyzOrNumber; let s = abcOrXyzOrNumber < abcOrXyzOrNumber; let t = abcOrXyzOrNumber >= abcOrXyz; let u = abc === abcOrXyz; let v = abcOrXyz === abcOrXyzOrNumber;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralTypesWithVariousOperators02.ts
TypeScript
// @declaration: true let abc: "ABC" = "ABC"; let xyz: "XYZ" = "XYZ"; let abcOrXyz: "ABC" | "XYZ" = abc || xyz; let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100; let a = abcOrXyzOrNumber + 100; let b = 100 + abcOrXyzOrNumber; let c = abcOrXyzOrNumber + abcOrXyzOrNumber; let d = abcOrXyzOrNumber + true; let e = false + abcOrXyzOrNumber; let f = abcOrXyzOrNumber++; let g = --abcOrXyzOrNumber; let h = abcOrXyzOrNumber ^ 10; let i = abcOrXyzOrNumber | 10; let j = abc < xyz; let k = abc === xyz; let l = abc != xyz;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsAssertionsInEqualityComparisons01.ts
TypeScript
var a = "foo" === "bar" as string; var b = "foo" !== ("bar" as string); var c = "foo" == (<any>"bar");
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsAssertionsInEqualityComparisons02.ts
TypeScript
type EnhancedString = string & { enhancements: any }; var a = "foo" === "bar" as "baz"; var b = "foo" !== ("bar" as "foo"); var c = "foo" == (<number>"bar"); var d = "foo" === ("bar" as EnhancedString);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsAssignedToStringMappings.ts
TypeScript
declare var x: Uppercase<Lowercase<string>>; // good x = "A"; // bad x = "a"; declare var y: Uppercase<Lowercase<`${number}`>>; // good y = "1"; // bad y = "a"; y = "A";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithEqualityChecks01.ts
TypeScript
let x: "foo"; let y: "foo" | "bar"; let b: boolean; b = x === y; b = "foo" === y b = y === "foo"; b = "foo" === "bar"; b = "bar" === x; b = x === "bar"; b = y === "bar"; b = "bar" === y; b = x !== y; b = "foo" !== y b = y !== "foo"; b = "foo" !== "bar"; b = "bar" !== x; b = x !== "bar"; b = y !== "bar"; b = "bar" !== y;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithEqualityChecks02.ts
TypeScript
let x: "foo"; let y: "foo" | "bar"; let b: boolean; b = x == y; b = "foo" == y b = y == "foo"; b = "foo" == "bar"; b = "bar" == x; b = x == "bar"; b = y == "bar"; b = "bar" == y; b = x != y; b = "foo" != y b = y != "foo"; b = "foo" != "bar"; b = "bar" != x; b = x != "bar"; b = y != "bar"; b = "bar" != y;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithEqualityChecks03.ts
TypeScript
interface Runnable { isRunning: boolean; } interface Refrigerator extends Runnable { makesFoodGoBrrr: boolean; } let x: string; let y: "foo" | Refrigerator; let b: boolean; b = x === y; b = "foo" === y b = y === "foo"; b = "foo" === "bar"; b = "bar" === x; b = x === "bar"; b = y === "bar"; b = "bar" === y; b = x !== y; b = "foo" !== y b = y !== "foo"; b = "foo" !== "bar"; b = "bar" !== x; b = x !== "bar"; b = y !== "bar"; b = "bar" !== y;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithEqualityChecks04.ts
TypeScript
interface Runnable { isRunning: boolean; } interface Refrigerator extends Runnable { makesFoodGoBrrr: boolean; } let x: string; let y: "foo" | Refrigerator; let b: boolean; b = x == y; b = "foo" == y b = y == "foo"; b = "foo" == "bar"; b = "bar" == x; b = x == "bar"; b = y == "bar"; b = "bar" == y; b = x != y; b = "foo" != y b = y != "foo"; b = "foo" != "bar"; b = "bar" != x; b = x != "bar"; b = y != "bar"; b = "bar" != y;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithSwitchStatements01.ts
TypeScript
let x: "foo"; let y: "foo" | "bar"; switch (x) { case "foo": break; case "bar": break; case y: y; break; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithSwitchStatements02.ts
TypeScript
let x: "foo"; let y: "foo" | "bar"; let b: boolean; b = x == y; b = "foo" == y b = y == "foo"; b = "foo" == "bar"; b = x != y; b = "foo" != y b = y != "foo"; b = "foo" != "bar";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithSwitchStatements03.ts
TypeScript
let x: "foo"; let y: "foo" | "bar"; let z: "bar"; declare function randBool(): boolean; switch (x) { case randBool() ? "foo" : "baz": break; case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): break; case (("bar")): break; case (x, y, ("baz")): x; y; break; case (("foo" || ("bar"))): break; case (("bar" || ("baz"))): break; case z || "baz": case "baz" || z: z; break; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithSwitchStatements04.ts
TypeScript
let x: "foo"; let y: "foo" | "bar"; declare function randBool(): boolean; switch (y) { case "foo", x: break; case x, "foo": break; case x, "baz": break; case "baz", x: break; case "baz" && "bar": break; case "baz" && ("foo" || "bar"): break; case "bar" && ("baz" || "bar"): break; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringLiteralsWithTypeAssertions01.ts
TypeScript
let fooOrBar: "foo" | "bar"; let a = "foo" as "bar"; let b = "bar" as "foo"; let c = fooOrBar as "foo"; let d = fooOrBar as "bar"; let e = fooOrBar as "baz"; let f = "baz" as typeof fooOrBar;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringMappingDeferralInConditionalTypes.ts
TypeScript
// @strict: true // @noEmit: true // https://github.com/microsoft/TypeScript/issues/55847 type A<S> = Lowercase<S & string> extends "foo" ? 1 : 0; let x1: A<"foo"> = 1; // ok type B<S> = Lowercase<S & string> extends `f${string}` ? 1 : 0; let x2: B<"foo"> = 1; // ok type C<S> = Capitalize<Lowercase<S & string>> extends "Foo" ? 1 : 0; let x3: C<"foo"> = 1; // ok type D<S extends string> = Capitalize<Lowercase<S>> extends "Foo" ? 1 : 0; let x4: D<"foo"> = 1; // ok type E<S> = Lowercase<`f${S & string}` & `${S & string}f`>; type F = E<""> extends "f" ? 1 : 0; // 1 type G<S> = E<S> extends "f" ? 1 : 0; let x5: G<""> = 1; // ok
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringMappingOverPatternLiterals.ts
TypeScript
// non-template type A = "aA"; type B = Uppercase<A>; type C = Lowercase<A>; // templated type ATemplate = `aA${string}`; type BTemplate = Uppercase<ATemplate>; type CTemplate = Lowercase<ATemplate>; function f1( a: A, b: B, c: C, a_template: ATemplate, b_template: BTemplate, c_template: CTemplate ) { // non-template versions should be assignable to templated versions (empty string matches string) a_template = a; b_template = b; c_template = c; // not the other way around a = a_template; b = b_template; c = c_template; // Additionally, all the template versions should be mutually incompatible (they describe differing sets) a_template = b_template; a_template = c_template; b_template = a_template; b_template = c_template; c_template = a_template; c_template = b_template; } // Raw string mapping assignability function f2(x1: string, x2: Uppercase<string>, x3: Lowercase<string>) { // ok x1 = x2; x1 = x3; x2 = "ABC"; x3 = "abc"; // should fail (sets do not match) x2 = x1; x2 = x3; x3 = x1; x3 = x2; x2 = "AbC"; x3 = "AbC"; } // Mappings over mappings function f3( x1: Uppercase<string>, x2: Uppercase<Uppercase<string>>, x3: Uppercase<Lowercase<string>>) { // _ideally_ these would all be equivalent x1 = x2; x1 = x3; x2 = x1; x2 = x3; // you'd think these were equivalent - the outer `Uppercase` conceptually // makes the inner `Lowercase` effectively a noop - but that's not so; // the german sharp s makes that not completely true (lowercases to ss, // which then uppercases to SS), so arbitrary nestings of mappings make differing sets! x3 = x1; x3 = x2; // and this should also not be equivlent to any others var x4: Lowercase<Uppercase<string>> = null as any; x1 = x4; x2 = x4; x3 = x4; x4 = x1; x4 = x2; x4 = x3; } // string mapping over non-string pattern literals is preserved type NonStringPat = Uppercase<`aA${number}${bigint}${boolean}`>; type EquivalentNonStringPat = `AA${Uppercase<`${number}`>}${Uppercase<`${bigint}`>}${Uppercase<`${boolean}`>}`; function f4(x1: NonStringPat, x2: EquivalentNonStringPat) { // Should both work x1 = x2; x2 = x1; } // Capitalize and uncapitalize on template literals function f5( cap_tem: `A${string}`, cap_str: Capitalize<string>, cap_tem_map: Capitalize<`A${string}`>, cap_tem_map2: Capitalize<`a${string}`>, uncap_tem: `a${string}`, uncap_str: Uncapitalize<string>, uncap_tem_map: Uncapitalize<`A${string}`>, uncap_tem_map2: Uncapitalize<`a${string}`>, ) { // All these are capitalized cap_str = cap_tem; cap_str = cap_tem_map; cap_str = cap_tem_map2; // these are all equivalent cap_tem = cap_tem_map; cap_tem = cap_tem_map2; cap_tem_map = cap_tem_map2; cap_tem_map = cap_tem; cap_tem_map2 = cap_tem_map; cap_tem_map2 = cap_tem; // meanwhile, these all require a `A` prefix cap_tem = cap_str; cap_tem_map = cap_str; cap_tem_map2 = cap_str; // All these are uncapitalized uncap_str = uncap_tem; uncap_str = uncap_tem_map; uncap_str = uncap_tem_map2; // these are all equivalent uncap_tem = uncap_tem_map; uncap_tem = uncap_tem_map2; uncap_tem_map = uncap_tem_map2; uncap_tem_map = uncap_tem; uncap_tem_map2 = uncap_tem_map; uncap_tem_map2 = uncap_tem; // meanwhile, these all require a `a` prefix uncap_tem = uncap_str; uncap_tem_map = uncap_str; uncap_tem_map2 = uncap_str; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringMappingReduction.ts
TypeScript
// @strict: true // @noEmit: true type T00 = "prop" | `p${Lowercase<string>}p`; // `p${Lowercase<string>}p` type T01 = "prop" | Lowercase<string>; // Lowercase<string> type T02 = "PROP" | Lowercase<string>; // "PROP" | Lowercase<string> type T10 = "prop" & `p${Lowercase<string>}p`; // "prop" type T11 = "prop" & Lowercase<string>; // "prop" type T12 = "PROP" & Lowercase<string>; // never type T20 = "prop" | Capitalize<string>; // "prop" | Capitalize<string> type T21 = "Prop" | Capitalize<string>; // Capitalize<string> type T22 = "PROP" | Capitalize<string>; // Capitalize<string> type T30 = "prop" & Capitalize<string>; // never type T31 = "Prop" & Capitalize<string>; // "Prop" type T32 = "PROP" & Capitalize<string>; // "PROP" // Repro from #57117 type EMap = { event: {} } type Keys = keyof EMap type EPlusFallback<C> = C extends Keys ? EMap[C] : "unrecognised event"; type VirtualEvent<T extends string> = { bivarianceHack(event: EPlusFallback<Lowercase<T>>): any; }['bivarianceHack']; declare const _virtualOn: (eventQrl: VirtualEvent<Keys>) => void; export const virtualOn = <T extends string>(eventQrl: VirtualEvent<T>) => { _virtualOn(eventQrl); };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringNamedPropertyAccess.ts
TypeScript
class C { "a b": number; static "c d": number; } var c: C; var r1 = c["a b"]; var r1b = C['c d']; interface I { "a b": number; } var i: I; var r2 = i["a b"]; var a: { "a b": number; } var r3 = a["a b"]; var b = { "a b": 1 } var r4 = b["a b"];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringPropertyAccess.ts
TypeScript
var x = ''; var a = x.charAt(0); var b = x.hasOwnProperty('charAt'); var c = x['charAt'](0); var e = x['hasOwnProperty']('toFixed');
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/stringPropertyAccessWithError.ts
TypeScript
var x = ''; var d = x['charAt']('invalid'); // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfAny.ts
TypeScript
// every type is a subtype of any, no errors expected interface I { [x: string]: any; foo: any; } interface I2 { [x: string]: any; foo: number; } interface I3 { [x: string]: any; foo: string; } interface I4 { [x: string]: any; foo: boolean; } interface I5 { [x: string]: any; foo: Date; } interface I6 { [x: string]: any; foo: RegExp; } interface I7 { [x: string]: any; foo: { bar: number }; } interface I8 { [x: string]: any; foo: number[]; } interface I9 { [x: string]: any; foo: I8; } class A { foo: number; } interface I10 { [x: string]: any; foo: A; } class A2<T> { foo: T; } interface I11 { [x: string]: any; foo: A2<number>; } interface I12 { [x: string]: any; foo: (x) => number; } interface I13 { [x: string]: any; foo: <T>(x:T) => T; } enum E { A } interface I14 { [x: string]: any; foo: E; } function f() { } module f { export var bar = 1; } interface I15 { [x: string]: any; foo: typeof f; } class c { baz: string } module c { export var bar = 1; } interface I16 { [x: string]: any; foo: typeof c; } interface I17<T> { [x: string]: any; foo: T; } interface I18<T, U> { [x: string]: any; foo: U; } //interface I18<T, U extends T> { // [x: string]: any; // foo: U; //} interface I19 { [x: string]: any; foo: Object; } interface I20 { [x: string]: any; foo: {}; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfTypeParameter.ts
TypeScript
// checking whether other types are subtypes of type parameters class C3<T> { foo: T; } class D1<T, U> extends C3<T> { foo: U; // error } function f1<T, U>(x: T, y: U) { var r = true ? x : y; // error var r = true ? y : x; // error } interface I1 { foo: number; } class C1 { foo: number; } class C2<T> { foo: T; } enum E { A } function f() { } module f { export var bar = 1; } class c { baz: string } module c { export var bar = 1; } // errors throughout function f2<T, U>(x: T, y: U) { var r0 = true ? x : null; var r0 = true ? null : x; var u: typeof undefined; var r0b = true ? u : x; var r0b = true ? x : u; var r1 = true ? 1 : x; var r1 = true ? x : 1; var r2 = true ? '' : x; var r2 = true ? x : ''; var r3 = true ? true : x; var r3 = true ? x : true; var r4 = true ? new Date() : x; var r4 = true ? x : new Date(); var r5 = true ? /1/ : x; var r5 = true ? x : /1/; var r6 = true ? { foo: 1 } : x; var r6 = true ? x : { foo: 1 }; var r7 = true ? () => { } : x; var r7 = true ? x : () => { }; var r8 = true ? <T>(x: T) => { return x } : x; var r8b = true ? x : <T>(x: T) => { return x }; // type parameters not identical across declarations var i1: I1; var r9 = true ? i1 : x; var r9 = true ? x : i1; var c1: C1; var r10 = true ? c1 : x; var r10 = true ? x : c1; var c2: C2<number>; var r12 = true ? c2 : x; var r12 = true ? x : c2; var r13 = true ? E : x; var r13 = true ? x : E; var r14 = true ? E.A : x; var r14 = true ? x : E.A; var af: typeof f; var r15 = true ? af : x; var r15 = true ? x : af; var ac: typeof c; var r16 = true ? ac : x; var r16 = true ? x : ac; function f17<T>(a: T) { var r17 = true ? x : a; var r17 = true ? a : x; } function f18<T, U extends T>(a: U) { var r18 = true ? x : a; var r18 = true ? a : x; } var r19 = true ? new Object() : x; // BCT is Object var r19 = true ? x : new Object(); // BCT is Object var r20 = true ? {} : x; // ok var r20 = true ? x : {}; // ok }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfTypeParameterWithConstraints.ts
TypeScript
// checking whether other types are subtypes of type parameters with constraints class C3<T> { foo: T; } class D1<T extends U, U> extends C3<T> { [x: string]: T; foo: T; // ok } class D2<T extends U, U> extends C3<U> { [x: string]: U; foo: T; // ok } class D3<T extends U, U> extends C3<T> { [x: string]: T; foo: U; // error } class D4<T extends U, U> extends C3<U> { [x: string]: U; foo: U; // ok } // V > U > T // test if T is subtype of T, U, V // should all work class D5<T extends U, U extends V, V> extends C3<T> { [x: string]: T; foo: T; // ok } class D6<T extends U, U extends V, V> extends C3<U> { [x: string]: U; foo: T; } class D7<T extends U, U extends V, V> extends C3<V> { [x: string]: V; foo: T; // ok } // test if U is a subtype of T, U, V // only a subtype of V and itself class D8<T extends U, U extends V, V> extends C3<T> { [x: string]: T; foo: U; // error } class D9<T extends U, U extends V, V> extends C3<U> { [x: string]: U; foo: U; // ok } class D10<T extends U, U extends V, V> extends C3<V> { [x: string]: V; foo: U; // ok } // test if V is a subtype of T, U, V // only a subtype of itself class D11<T extends U, U extends V, V> extends C3<T> { [x: string]: T; foo: V; // error } class D12<T extends U, U extends V, V> extends C3<U> { [x: string]: U; foo: V; // error } class D13<T extends U, U extends V, V> extends C3<V> { [x: string]: V; foo: V; // ok } // Date > V > U > T // test if T is subtype of T, U, V, Date // should all work class D14<T extends U, U extends V, V extends Date> extends C3<Date> { [x: string]: Date; foo: T; // ok } class D15<T extends U, U extends V, V extends Date> extends C3<T> { [x: string]: T; foo: T; // ok } class D16<T extends U, U extends V, V extends Date> extends C3<U> { [x: string]: U; foo: T; } class D17<T extends U, U extends V, V extends Date> extends C3<V> { [x: string]: V; foo: T; } // test if U is a subtype of T, U, V, Date // only a subtype of V, Date and itself class D18<T extends U, U extends V, V extends Date> extends C3<Date> { [x: string]: Date; foo: T; // ok } class D19<T extends U, U extends V, V extends Date> extends C3<T> { [x: string]: T; foo: U; // error } class D20<T extends U, U extends V, V extends Date> extends C3<U> { [x: string]: U; foo: U; // ok } class D21<T extends U, U extends V, V extends Date> extends C3<V> { [x: string]: V; foo: U; } // test if V is a subtype of T, U, V, Date // only a subtype of itself and Date class D22<T extends U, U extends V, V extends Date> extends C3<Date> { [x: string]: Date; foo: T; // ok } class D23<T extends U, U extends V, V extends Date> extends C3<T> { [x: string]: T; foo: V; // error } class D24<T extends U, U extends V, V extends Date> extends C3<U> { [x: string]: U; foo: V; // error } class D25<T extends U, U extends V, V extends Date> extends C3<V> { [x: string]: V; foo: V; // ok } // test if Date is a subtype of T, U, V, Date // only a subtype of itself class D26<T extends U, U extends V, V extends Date> extends C3<Date> { [x: string]: Date; foo: Date; // ok } class D27<T extends U, U extends V, V extends Date> extends C3<T> { [x: string]: T; foo: Date; // error } class D28<T extends U, U extends V, V extends Date> extends C3<U> { [x: string]: U; foo: Date; // error } class D29<T extends U, U extends V, V extends Date> extends C3<V> { [x: string]: V; foo: Date; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfTypeParameterWithConstraints2.ts
TypeScript
// checking whether other types are subtypes of type parameters with constraints function f1<T extends U, U>(x: T, y: U) { var r = true ? x : y; var r = true ? y : x; } // V > U > T function f2<T extends U, U extends V, V>(x: T, y: U, z: V) { var r = true ? x : y; var r = true ? y : x; // ok var r2 = true ? z : y; var r2 = true ? y : z; // ok var r2a = true ? z : x; var r2b = true ? x : z; } // Date > U > T function f3<T extends U, U extends Date>(x: T, y: U) { var r = true ? x : y; var r = true ? y : x; // ok var r2 = true ? x : new Date(); var r2 = true ? new Date() : x; // ok var r3 = true ? y : new Date(); var r3 = true ? new Date() : y; } interface I1 { foo: number; } class C1 { foo: number; } class C2<T> { foo: T; } enum E { A } function f() { } module f { export var bar = 1; } class c { baz: string } module c { export var bar = 1; } function f4<T extends Number>(x: T) { var r0 = true ? x : null; // ok var r0 = true ? null : x; // ok var u: typeof undefined; var r0b = true ? u : x; // ok var r0b = true ? x : u; // ok } function f5<T extends Number>(x: T) { var r1 = true ? 1 : x; // ok var r1 = true ? x : 1; // ok } function f6<T extends String>(x: T) { var r2 = true ? '' : x; // ok var r2 = true ? x : ''; // ok } function f7<T extends Boolean>(x: T) { var r3 = true ? true : x; // ok var r3 = true ? x : true; // ok } function f8<T extends Date>(x: T) { var r4 = true ? new Date() : x; // ok var r4 = true ? x : new Date(); // ok } function f9<T extends RegExp>(x: T) { var r5 = true ? /1/ : x; // ok var r5 = true ? x : /1/; // ok } function f10<T extends { foo: number }>(x: T) { var r6 = true ? { foo: 1 } : x; // ok var r6 = true ? x : { foo: 1 }; // ok } function f11<T extends () => void>(x: T) { var r7 = true ? () => { } : x; // ok var r7 = true ? x : () => { }; // ok } function f12<T extends <U>(x: U) => U>(x: T) { var r8 = true ? <T>(x: T) => { return x } : x; // ok var r8b = true ? x : <T>(x: T) => { return x }; // ok, type parameters not identical across declarations } function f13<T extends I1>(x: T) { var i1: I1; var r9 = true ? i1 : x; // ok var r9 = true ? x : i1; // ok } function f14<T extends C1>(x: T) { var c1: C1; var r10 = true ? c1 : x; // ok var r10 = true ? x : c1; // ok } function f15<T extends C2<number>>(x: T) { var c2: C2<number>; var r12 = true ? c2 : x; // ok var r12 = true ? x : c2; // ok } function f16<T extends E>(x: T) { var r13 = true ? E : x; // ok var r13 = true ? x : E; // ok var r14 = true ? E.A : x; // ok var r14 = true ? x : E.A; // ok } function f17<T extends typeof f>(x: T) { var af: typeof f; var r15 = true ? af : x; // ok var r15 = true ? x : af; // ok } function f18<T extends typeof c>(x: T) { var ac: typeof c; var r16 = true ? ac : x; // ok var r16 = true ? x : ac; // ok } function f19<T>(x: T) { function f17<U extends T>(a: U) { var r17 = true ? x : a; // ok var r17 = true ? a : x; // ok } function f18<V extends U, U extends T>(a: V) { var r18 = true ? x : a; // ok var r18 = true ? a : x; // ok } } function f20<T extends Number>(x: T) { var r19 = true ? new Object() : x; // ok var r19 = true ? x : new Object(); // ok } function f21<T extends Number>(x: T) { var r20 = true ? {} : x; // ok var r20 = true ? x : {}; // ok }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfTypeParameterWithConstraints3.ts
TypeScript
// checking whether other types are subtypes of type parameters with constraints function f<T extends U, U, V>(t: T, u: U, v: V) { // ok var r = true ? t : u; var r = true ? u : t; // ok var r2 = true ? t : v; var r2 = true ? v : t; // ok var r3 = true ? v : u; var r3 = true ? u : v; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfTypeParameterWithConstraints4.ts
TypeScript
// checking whether other types are subtypes of type parameters with constraints class Foo { foo: number; } function f<T extends Foo, U extends Foo, V>(t: T, u: U, v: V) { // ok var r = true ? t : u; var r = true ? u : t; // ok var r2 = true ? t : v; var r2 = true ? v : t; // ok var r3 = true ? v : u; var r3 = true ? u : v; // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; } class B1<T> { foo: T; } class D1<T extends Foo, U extends Foo, V> extends B1<Foo> { [x: string]: Foo; foo: T; // ok } class D2<T extends Foo, U extends Foo, V> extends B1<Foo> { [x: string]: Foo; foo: U; // ok } class D3<T extends Foo, U extends Foo, V> extends B1<Foo> { [x: string]: Foo; foo: V; // error } class D4<T extends Foo, U extends Foo, V> extends B1<T> { [x: string]: T; foo: T; // ok } class D5<T extends Foo, U extends Foo, V> extends B1<T> { [x: string]: T; foo: U; // error } class D6<T extends Foo, U extends Foo, V> extends B1<T> { [x: string]: T; foo: V; // error } class D7<T extends Foo, U extends Foo, V> extends B1<U> { [x: string]: U; foo: T; // error } class D8<T extends Foo, U extends Foo, V> extends B1<U> { [x: string]: U; foo: U; // ok } class D9<T extends Foo, U extends Foo, V> extends B1<U> { [x: string]: U; foo: V; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfTypeParameterWithRecursiveConstraints.ts
TypeScript
// checking whether other types are subtypes of type parameters with constraints class Foo<T> { foo: T; } function f<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>>(t: T, u: U, v: V) { // ok var r1 = true ? t : u; var r1 = true ? u : t; // ok var r2 = true ? t : v; var r2 = true ? v : t; // ok var r3 = true ? v : u; var r3 = true ? u : v; // ok var r4 = true ? t : new Foo<T>(); var r4 = true ? new Foo<T>() : t; // ok var r5 = true ? u : new Foo<T>(); var r5 = true ? new Foo<T>() : u; // ok var r6 = true ? v : new Foo<T>(); var r6 = true ? new Foo<T>() : v; // ok var r7 = true ? t : new Foo<U>(); var r7 = true ? new Foo<U>() : t; // ok var r8 = true ? u : new Foo<U>(); var r8 = true ? new Foo<U>() : u; // ok var r9 = true ? v : new Foo<U>(); var r9 = true ? new Foo<U>() : v; // ok var r10 = true ? t : new Foo<V>(); var r10 = true ? new Foo<V>() : t; // ok var r11 = true ? u : new Foo<V>(); var r11 = true ? new Foo<V>() : u; // ok var r12 = true ? v : new Foo<V>(); var r12 = true ? new Foo<V>() : v; } module M1 { class Base<T> { foo: T; } class D1<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<T> { [x: string]: T; foo: T } class D2<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<T> { [x: string]: T; foo: U } class D3<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<T> { [x: string]: T; foo: V } class D4<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<U> { [x: string]: U; foo: T } class D5<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<U> { [x: string]: U; foo: U } class D6<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<U> { [x: string]: U; foo: V } class D7<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<V> { [x: string]: V; foo: T } class D8<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<V> { [x: string]: V; foo: U } class D9<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base<V> { [x: string]: V; foo: V } } module M2 { class Base2<T> { foo: Foo<T>; } class D1<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<T> { [x: string]: T; foo: T } class D2<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<T> { [x: string]: T; foo: U } class D3<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<T> { [x: string]: T; foo: V } class D4<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<U> { [x: string]: U; foo: T } class D5<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<U> { [x: string]: U; foo: U } class D6<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<U> { [x: string]: U; foo: V } class D7<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<V> { [x: string]: V; foo: T } class D8<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<V> { [x: string]: V; foo: U } class D9<T extends Foo<U>, U extends Foo<T>, V extends Foo<V>> extends Base2<V> { [x: string]: V; foo: V } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypesOfUnion.ts
TypeScript
enum E { e1, e2 } interface I8 { [x: string]: number[]; } class A { foo: number; } class A2<T> { foo: T; } function f() { } module f { export var bar = 1; } class c { baz: string } module c { export var bar = 1; } // A type T is a subtype of a union type U if T is a subtype of any type in U. interface I1<T> { [x: string]: string | number; foo: any; // ok foo2: string; // ok foo3: number; // ok foo4: boolean; // error foo5: E; // ok - subtype of number foo6: Date; // error foo7: RegExp; // error foo8: { bar: number }; // error foo9: I8; // error foo10: A; // error foo11: A2<number>; // error foo12: (x) => number; //error foo13: <T>(x: T) => T; // error foo14: typeof f; // error foo15: typeof c; // error foo16: T; // error foo17: Object; // error foo18: {}; // error } interface I2<T> { [x: string]: E | number; foo: any; // ok foo2: string; // error foo3: number; // ok foo4: boolean; // error foo5: E; // ok foo6: Date; // error foo7: RegExp; // error foo8: { bar: number }; // error foo9: I8; // error foo10: A; // error foo11: A2<number>; // error foo12: (x) => number; //error foo13: <T>(x: T) => T; // error foo14: typeof f; // error foo15: typeof c; // error foo16: T; // error foo17: Object; // error foo18: {}; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignatures.ts
TypeScript
module CallSignature { declare function foo1(cb: (x: number) => void): typeof cb; declare function foo1(cb: any): any; var r = foo1((x: number) => 1); // ok because base returns void var r2 = foo1(<T>(x: T) => ''); // ok because base returns void declare function foo2(cb: (x: number, y: number) => void): typeof cb; declare function foo2(cb: any): any; var r3 = foo2((x: number, y: number) => 1); // ok because base returns void var r4 = foo2(<T>(x: T) => ''); // ok because base returns void }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignatures2.ts
TypeScript
// checking subtype relations for function types as it relates to contextual signature instantiation class Base { foo: string; } class Derived extends Base { bar: string; } class Derived2 extends Derived { baz: string; } class OtherDerived extends Base { bing: string; } declare function foo1(a: (x: number) => number[]): typeof a; declare function foo1(a: any): any; declare function foo2(a: (x: number) => string[]): typeof a; declare function foo2(a: any): any; declare function foo3(a: (x: number) => void): typeof a; declare function foo3(a: any): any; declare function foo4(a: (x: string, y: number) => string): typeof a; declare function foo4(a: any): any; declare function foo5(a: (x: (arg: string) => number) => string): typeof a; declare function foo5(a: any): any; declare function foo6(a: (x: (arg: Base) => Derived) => Base): typeof a; declare function foo6(a: any): any; declare function foo7(a: (x: (arg: Base) => Derived) => (r: Base) => Derived): typeof a; declare function foo7(a: any): any; declare function foo8(a: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): typeof a; declare function foo8(a: any): any; declare function foo9(a: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): typeof a; declare function foo9(a: any): any; declare function foo10(a: (...x: Derived[]) => Derived): typeof a; declare function foo10(a: any): any; declare function foo11(a: (x: { foo: string }, y: { foo: string; bar: string }) => Base): typeof a; declare function foo11(a: any): any; declare function foo12(a: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>): typeof a; declare function foo12(a: any): any; declare function foo13(a: (x: Array<Base>, y: Array<Derived>) => Array<Derived>): typeof a; declare function foo13(a: any): any; declare function foo14(a: (x: { a: string; b: number }) => Object): typeof a; declare function foo14(a: any): any; declare function foo15(a: { (x: number): number[]; (x: string): string[]; }): typeof a; declare function foo15(a: any): any; declare function foo16(a: { <T extends Derived>(x: T): number[]; <U extends Base>(x: U): number[]; }): typeof a; declare function foo16(a: any): any; declare function foo17(a: { (x: (a: number) => number): number[]; (x: (a: string) => string): string[]; }): typeof a; declare function foo17(a: any): any; declare function foo18(a: { (x: { (a: number): number; (a: string): string; }): any[]; (x: { (a: boolean): boolean; (a: Date): Date; }): any[]; }): typeof a; declare function foo18(a: any): any; var r1arg1 = <T>(x: T) => [x]; var r1arg2 = (x: number) => [1]; var r1 = foo1(r1arg1); // any, return types are not subtype of first overload var r1a = [r1arg2, r1arg1]; // generic signature, subtype in both directions var r1b = [r1arg1, r1arg2]; // generic signature, subtype in both directions var r2arg1 = <T>(x: T) => ['']; var r2arg2 = (x: number) => ['']; var r2 = foo2(r2arg1); var r2a = [r2arg1, r2arg2]; var r2b = [r2arg2, r2arg1]; var r3arg1 = <T>(x: T) => x; var r3arg2 = (x: number) => { }; var r3 = foo3(r3arg1); var r3a = [r3arg1, r3arg2]; var r3b = [r3arg2, r3arg1]; var r4arg1 = <T, U>(x: T, y: U) => x; var r4arg2 = (x: string, y: number) => ''; var r4 = foo4(r4arg1); // any var r4a = [r4arg1, r4arg2]; var r4b = [r4arg2, r4arg1]; var r5arg1 = <T, U>(x: (arg: T) => U) => <T>null; var r5arg2 = (x: (arg: string) => number) => ''; var r5 = foo5(r5arg1); // any var r5a = [r5arg1, r5arg2]; var r5b = [r5arg2, r5arg1]; var r6arg1 = <T extends Base, U extends Derived>(x: (arg: T) => U) => <T>null; var r6arg2 = (x: (arg: Base) => Derived) => <Base>null; var r6 = foo6(r6arg1); // any var r6a = [r6arg1, r6arg2]; var r6b = [r6arg2, r6arg1]; var r7arg1 = <T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => <U>null; var r7arg2 = (x: (arg: Base) => Derived) => (r: Base) => <Derived>null; var r7 = foo7(r7arg1); // any var r7a = [r7arg1, r7arg2]; var r7b = [r7arg2, r7arg1]; var r8arg1 = <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => <U>null; var r8arg2 = (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => <Derived>null; var r8 = foo8(r8arg1); // any var r8a = [r8arg1, r8arg2]; var r8b = [r8arg2, r8arg1]; var r9arg1 = <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => <U>null; var r9arg2 = (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => <Derived>null; var r9 = foo9(r9arg1); // any var r9a = [r9arg1, r9arg2]; var r9b = [r9arg2, r9arg1]; var r10arg1 = <T extends Derived>(...x: T[]) => x[0]; var r10arg2 = (...x: Derived[]) => <Derived>null; var r10 = foo10(r10arg1); // any var r10a = [r10arg1, r10arg2]; var r10b = [r10arg2, r10arg1]; var r11arg1 = <T extends Base>(x: T, y: T) => x; var r11arg2 = (x: { foo: string }, y: { foo: string; bar: string }) => <Base>null; var r11 = foo11(r11arg1); // any var r11a = [r11arg1, r11arg2]; var r11b = [r11arg2, r11arg1]; var r12arg1 = <T extends Array<Base>>(x: Array<Base>, y: T) => <Array<Derived>>null; var r12arg2 = (x: Array<Base>, y: Array<Derived2>) => <Array<Derived>>null; var r12 = foo12(r12arg1); // any var r12a = [r12arg1, r12arg2]; var r12b = [r12arg2, r12arg1]; var r13arg1 = <T extends Array<Derived>>(x: Array<Base>, y: T) => y; var r13arg2 = (x: Array<Base>, y: Array<Derived>) => <Array<Derived>>null; var r13 = foo13(r13arg1); // any var r13a = [r13arg1, r13arg2]; var r13b = [r13arg2, r13arg1]; var r14arg1 = <T>(x: { a: T; b: T }) => x.a; var r14arg2 = (x: { a: string; b: number }) => <Object>null; var r14 = foo14(r14arg1); // any var r14a = [r14arg1, r14arg2]; var r14b = [r14arg2, r14arg1]; var r15arg1 = <T>(x: T) => <T[]>null var r15 = foo15(r15arg1); // any var r16arg1 = <T extends Base>(x: T) => [1]; var r16 = foo16(r16arg1); var r17arg1 = <T>(x: (a: T) => T) => <T[]>null; var r17 = foo17(r17arg1); // any var r18arg1 = <T>(x: (a: T) => T) => <T[]>null; var r18 = foo18(r18arg1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignatures3.ts
TypeScript
// checking subtype relations for function types as it relates to contextual signature instantiation // error cases, so function calls will all result in 'any' module Errors { class Base { foo: string; } class Derived extends Base { bar: string; } class Derived2 extends Derived { baz: string; } class OtherDerived extends Base { bing: string; } declare function foo2(a2: (x: number) => string[]): typeof a2; declare function foo2(a2: any): any; declare function foo7(a2: (x: (arg: Base) => Derived) => (r: Base) => Derived2): typeof a2; declare function foo7(a2: any): any; declare function foo8(a2: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): typeof a2; declare function foo8(a2: any): any; declare function foo10(a2: (...x: Base[]) => Base): typeof a2; declare function foo10(a2: any): any; declare function foo11(a2: (x: { foo: string }, y: { foo: string; bar: string }) => Base): typeof a2; declare function foo11(a2: any): any; declare function foo12(a2: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>): typeof a2; declare function foo12(a2: any): any; declare function foo15(a2: (x: { a: string; b: number }) => number): typeof a2; declare function foo15(a2: any): any; declare function foo16(a2: { // type of parameter is overload set which means we can't do inference based on this type (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }): typeof a2; declare function foo16(a2: any): any; declare function foo17(a2: { (x: { <T extends Derived>(a: T): T; <T extends Base>(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[]; }): typeof a2; declare function foo17(a2: any): any; var r1 = foo2(<T, U>(x: T) => <U[]>null); // any var r1a = [(x: number) => [''], <T, U>(x: T) => <U[]>null]; var r1b = [<T, U>(x: T) => <U[]>null, (x: number) => ['']]; var r2arg = <T extends Base, U extends Derived, V extends Derived2>(x: (arg: T) => U) => (r: T) => <V>null; var r2arg2 = (x: (arg: Base) => Derived) => (r: Base) => <Derived2>null; var r2 = foo7(r2arg); // any var r2a = [r2arg2, r2arg]; var r2b = [r2arg, r2arg2]; var r3arg = <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => <U>null; var r3arg2 = (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => <Derived>null; var r3 = foo8(r3arg); // any var r3a = [r3arg2, r3arg]; var r3b = [r3arg, r3arg2]; var r4arg = <T extends Derived>(...x: T[]) => <T>null; var r4arg2 = (...x: Base[]) => <Base>null; var r4 = foo10(r4arg); // any var r4a = [r4arg2, r4arg]; var r4b = [r4arg, r4arg2]; var r5arg = <T extends Derived>(x: T, y: T) => <T>null; var r5arg2 = (x: { foo: string }, y: { foo: string; bar: string }) => <Base>null; var r5 = foo11(r5arg); // any var r5a = [r5arg2, r5arg]; var r5b = [r5arg, r5arg2]; var r6arg = (x: Array<Base>, y: Array<Derived2>) => <Array<Derived>>null; var r6arg2 = <T extends Array<Derived2>>(x: Array<Base>, y: Array<Base>) => <T>null; var r6 = foo12(r6arg); // (x: Array<Base>, y: Array<Derived2>) => Array<Derived> var r6a = [r6arg2, r6arg]; var r6b = [r6arg, r6arg2]; var r7arg = <T>(x: { a: T; b: T }) => <T>null; var r7arg2 = (x: { a: string; b: number }) => 1; var r7 = foo15(r7arg); // any var r7a = [r7arg2, r7arg]; var r7b = [r7arg, r7arg2]; var r7arg3 = <T extends Base>(x: { a: T; b: T }) => 1; var r7c = foo15(r7arg3); // (x: { a: string; b: number }) => number): number; var r7d = [r7arg2, r7arg3]; var r7e = [r7arg3, r7arg2]; var r8arg = <T>(x: (a: T) => T) => <T[]>null; var r8 = foo16(r8arg); // any var r9arg = <T>(x: (a: T) => T) => <any[]>null; var r9 = foo17(r9arg); // (x: { <T extends Derived >(a: T): T; <T extends Base >(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[]; } module WithGenericSignaturesInBaseType { declare function foo2(a2: <T>(x: T) => T[]): typeof a2; declare function foo2(a2: any): any; var r2arg2 = <T>(x: T) => ['']; var r2 = foo2(r2arg2); // <T>(x:T) => T[] since we can infer from generic signatures now declare function foo3(a2: <T>(x: T) => string[]): typeof a2; declare function foo3(a2: any): any; var r3arg2 = <T>(x: T) => <T[]>null; var r3 = foo3(r3arg2); // any }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignatures4.ts
TypeScript
// checking subtype relations for function types as it relates to contextual signature instantiation class Base { foo: string; } class Derived extends Base { bar: string; } class Derived2 extends Derived { baz: string; } class OtherDerived extends Base { bing: string; } declare function foo1(a: <T>(x: T) => T[]); declare function foo1(a: any): any; declare function foo2(a2: <T>(x: T) => string[]); declare function foo2(a: any): any; declare function foo3(a3: <T>(x: T) => void); declare function foo3(a: any): any; declare function foo4(a4: <T, U>(x: T, y: U) => string); declare function foo4(a: any): any; declare function foo5(a5: <T, U>(x: (arg: T) => U) => T); declare function foo5(a: any): any; declare function foo6(a6: <T extends Base>(x: (arg: T) => Derived) => T); declare function foo6(a: any): any; declare function foo11(a11: <T>(x: { foo: T }, y: { foo: T; bar: T }) => Base); declare function foo11(a: any): any; declare function foo15(a15: <T>(x: { a: T; b: T }) => T[]); declare function foo15(a: any): any; declare function foo16(a16: <T extends Base>(x: { a: T; b: T }) => T[]); declare function foo16(a: any): any; declare function foo17(a17: { <T extends Derived>(x: (a: T) => T): T[]; <T extends Base>(x: (a: T) => T): T[]; }); declare function foo17(a: any): any; declare function foo18(a18: { (x: { <T extends Derived>(a: T): T; <T extends Base>(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[]; }); declare function foo18(a: any): any; var r1arg = <T>(x: T) => <T[]>null; var r1arg2 = <T>(x: T) => <T[]>null; var r1 = foo1(r1arg); var r1a = [r1arg, r1arg2]; var r1b = [r1arg2, r1arg]; var r2arg = <T>(x: T) => ['']; var r2arg2 = <T>(x: T) => ['']; var r2 = foo2(r2arg); var r2a = [r2arg, r2arg2]; var r2b = [r2arg2, r2arg]; var r3arg = <T>(x: T) => <T>null; var r3arg2 = <T>(x: T) => { }; var r3 = foo3(r3arg); var r3a = [r3arg, r3arg2]; var r3b = [r3arg2, r3arg]; var r4arg = <T, U>(x: T, y: U) => ''; var r4arg2 = <T, U>(x: T, y: U) => ''; var r4 = foo4(r4arg); var r4a = [r4arg, r4arg2]; var r4b = [r4arg2, r4arg]; var r5arg = <T, U>(x: (arg: T) => U) => <T>null; var r5arg2 = <T, U>(x: (arg: T) => U) => <T>null; var r5 = foo5(r5arg); var r5a = [r5arg, r5arg2]; var r5b = [r5arg2, r5arg]; var r6arg = <T extends Base, U extends Derived>(x: (arg: T) => U) => <T>null; var r6arg2 = <T extends Base>(x: (arg: T) => Derived) => <T>null; var r6 = foo6(r6arg); var r6a = [r6arg, r6arg2]; var r6b = [r6arg2, r6arg]; var r11arg = <T, U>(x: { foo: T }, y: { foo: U; bar: U }) => <Base>null; var r11arg2 = <T>(x: { foo: T }, y: { foo: T; bar: T }) => <Base>null; var r11 = foo11(r11arg); var r11a = [r11arg, r11arg2]; var r11b = [r11arg2, r11arg]; var r15arg = <U, V>(x: { a: U; b: V; }) => <U[]>null; var r15arg2 = <T>(x: { a: T; b: T }) => <T[]>null; var r15 = foo15(r15arg); var r15a = [r15arg, r15arg2]; var r15b = [r15arg2, r15arg]; var r16arg = <T extends Base>(x: { a: T; b: T }) => <T[]>null; var r16arg2 = <T extends Base>(x: { a: T; b: T }) => <T[]>null; var r16 = foo16(r16arg); var r16a = [r16arg, r16arg2]; var r16b = [r16arg2, r16arg]; var r17arg = <T>(x: (a: T) => T) => <T[]>null; var r17 = foo17(r17arg); var r18arg = (x: <T>(a: T) => T) => <any[]>null; var r18 = foo18(r18arg);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignaturesA.ts
TypeScript
declare function foo3(cb: (x: number) => number): typeof cb; var r5 = foo3((x: number) => ''); // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignaturesWithOptionalParameters.ts
TypeScript
// call signatures in derived types must have the same or fewer optional parameters as the base type interface Base { a: () => number; a2: (x?: number) => number; a3: (x: number) => number; a4: (x: number, y?: number) => number; a5: (x?: number, y?: number) => number; } interface I1 extends Base { a: () => number; // ok, same number of required params } interface I2 extends Base { a: (x?: number) => number; // ok, same number of required params } interface I3 extends Base { a: (x: number) => number; // error, too many required params } interface I4 extends Base { a2: () => number; // ok, same number of required params } interface I5 extends Base { a2: (x?: number) => number; // ok, same number of required params } interface I6 extends Base { a2: (x: number) => number; // ok, same number of params } interface I7 extends Base { a3: () => number; // ok, fewer required params } interface I8 extends Base { a3: (x?: number) => number; // ok, fewer required params } interface I9 extends Base { a3: (x: number) => number; // ok, same number of required params } interface I10 extends Base { a3: (x: number, y: number) => number; // error, too many required params } interface I11 extends Base { a4: () => number; // ok, fewer required params } interface I12 extends Base { a4: (x?: number, y?: number) => number; // ok, fewer required params } interface I13 extends Base { a4: (x: number) => number; // ok, same number of required params } interface I14 extends Base { a4: (x: number, y: number) => number; // ok, same number of params } interface I15 extends Base { a5: () => number; // ok, fewer required params } interface I16 extends Base { a5: (x?: number, y?: number) => number; // ok, fewer required params } interface I17 extends Base { a5: (x: number) => number; // ok, all present params match } interface I18 extends Base { a5: (x: number, y: number) => number; // ok, same number of params }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignaturesWithRestParameters.ts
TypeScript
// call signatures in derived types must have the same or fewer optional parameters as the base type interface Base { a: (...args: number[]) => number; a2: (x: number, ...z: number[]) => number; a3: (x: number, y?: string, ...z: number[]) => number; a4: (x?: number, y?: string, ...z: number[]) => number; } interface I1 extends Base { a: () => number; // ok, same number of required params } interface I1B extends Base { a: (...args: number[]) => number; // ok, same number of required params } interface I1C extends Base { a: (...args: string[]) => number; // error, type mismatch } interface I2 extends Base { a: (x?: number) => number; // ok, same number of required params } interface I2B extends Base { a: (x?: number, y?: number, z?: number) => number; // ok, same number of required params } interface I3 extends Base { a: (x: number) => number; // ok, all present params match } interface I3B extends Base { a: (x?: string) => number; // error, incompatible type } interface I4 extends Base { a2: () => number; // ok, fewer required params } interface I4B extends Base { a2: (...args: number[]) => number; // ok, fewer required params } interface I5 extends Base { a2: (x?: number) => number; // ok, fewer required params } interface I6 extends Base { a2: (x: number) => number; // ok, same number of required params } interface I6B extends Base { a2: (x: number, ...args: number[]) => number; // ok, same number of required params } interface I6C extends Base { a2: (x: number, ...args: string[]) => number; // error } interface I6D extends Base { a2: (x: number, y: number) => number; // ok, all present params match } interface I6E extends Base { a2: (x: number, y?: number) => number; // ok, same number of required params } interface I7 extends Base { a3: () => number; // ok, fewer required params } interface I8 extends Base { a3: (x?: number) => number; // ok, fewer required params } interface I9 extends Base { a3: (x: number) => number; // ok, same number of required params } interface I10 extends Base { a3: (x: number, y: string) => number; // ok, all present params match } interface I10B extends Base { a3: (x: number, y?: number, z?: number) => number; // error } interface I10C extends Base { a3: (x: number, ...z: number[]) => number; // error } interface I10D extends Base { a3: (x: string, y?: string, z?: string) => number; // error, incompatible types } interface I10E extends Base { a3: (x: number, ...z: string[]) => number; // error } interface I11 extends Base { a4: () => number; // ok, fewer required params } interface I12 extends Base { a4: (x?: number, y?: number) => number; // error, type mismatch } interface I13 extends Base { a4: (x: number) => number; // ok, all present params match } interface I14 extends Base { a4: (x: number, y?: number) => number; // error, second param has type mismatch } interface I15 extends Base { a4: (x?: number, y?: string) => number; // ok, same number of required params with matching types } interface I16 extends Base { a4: (x: number, ...args: string[]) => number; // error, rest param has type mismatch } interface I17 extends Base { a4: (...args: number[]) => number; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithCallSignaturesWithSpecializedSignatures.ts
TypeScript
// same as subtypingWithCallSignatures but with additional specialized signatures that should not affect the results module CallSignature { interface Base { // T // M's (x: 'a'): void; (x: string, y: number): void; } // S's interface I extends Base { // N's (x: 'a'): number; // ok because base returns void (x: string, y: number): number; // ok because base returns void <T>(x: T): string; // ok because base returns void } interface Base2 { // T // M's (x: 'a'): number; (x: string): number; } // S's interface I2 extends Base2 { // N's (x: 'a'): string; (x: string): string; // error because base returns non-void; } // S's interface I3 extends Base2 { // N's <T>(x: T): string; // ok, adds a new call signature } } module MemberWithCallSignature { interface Base { // T // M's a: { (x: 'a'): void; (x: string): void; } a2: { (x: 'a', y: number): void; (x: string, y: number): void; } a3: <T>(x: T) => void; } // S's interface I extends Base { // N's a: (x: string) => number; // ok because base returns void a2: (x: string, y: number) => boolean; // ok because base returns void a3: <T>(x: T) => string; // ok because base returns void } interface Base2 { // T // M's a: { (x: 'a'): number; (x: string): number; } a2: <T>(x: T) => T; } // S's interface I2 extends Base2 { // N's a: (x: string) => string; // error because base returns non-void; } // S's interface I3 extends Base2 { // N's a2: <T>(x: T) => string; // error because base returns non-void; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/subtypingWithConstructSignatures.ts
TypeScript
module ConstructSignature { declare function foo1(cb: new (x: number) => void): typeof cb; declare function foo1(cb: any): any; var rarg1: new (x: number) => number; var r = foo1(rarg1); // ok because base returns void var rarg2: new <T>(x: T) => string; var r2 = foo1(rarg2); // ok because base returns void declare function foo2(cb: new (x: number, y: number) => void): typeof cb; declare function foo2(cb: any): any; var r3arg1: new (x: number, y: number) => number; var r3 = foo2(r3arg1); // ok because base returns void var r4arg1: new <T>(x: T) => string; var r4 = foo2(r4arg1); // ok because base returns void }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University