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/independentPropertyVariance.ts
TypeScript
// @strict: true // Verify that properties can vary independently in comparable relationship declare const x: { a: 1, b: string }; declare const y: { a: number, b: 'a' }; x === y;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/indexSignatureTypeInference.ts
TypeScript
interface NumberMap<T> { [index: number]: T; } interface StringMap<T> { [index: string]: T; } declare function numberMapToArray<T>(object: NumberMap<T>): T[]; declare function stringMapToArray<T>(object: StringMap<T>): T[]; var numberMap: NumberMap<Function>; var stringMap: StringMap<Function>; var v1: Function[]; var v1 = numberMapToArray(numberMap); // Ok var v1 = numberMapToArray(stringMap); // Ok var v1 = stringMapToArray(numberMap); // Error expected here var v1 = stringMapToArray(stringMap); // Ok
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/indexerWithTuple.ts
TypeScript
var strNumTuple: [string, number] = ["foo", 10]; var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]]; var unionTuple1: [number, string| number] = [10, "foo"]; var unionTuple2: [boolean, string| number] = [true, "foo"]; // no error var idx0 = 0; var idx1 = 1; var ele10 = strNumTuple[0]; // string var ele11 = strNumTuple[1]; // number var ele12 = strNumTuple[2]; // string | number var ele13 = strNumTuple[idx0]; // string | number var ele14 = strNumTuple[idx1]; // string | number var ele15 = strNumTuple["0"]; // string var ele16 = strNumTuple["1"]; // number var strNumTuple1 = numTupleTuple[1]; //[string, number]; var ele17 = numTupleTuple[2]; // number | [string, number] var ele19 = strNumTuple[-1] // undefined var eleUnion10 = unionTuple1[0]; // number var eleUnion11 = unionTuple1[1]; // string | number var eleUnion12 = unionTuple1[2]; // string | number var eleUnion13 = unionTuple1[idx0]; // string | number var eleUnion14 = unionTuple1[idx1]; // string | number var eleUnion15 = unionTuple1["0"]; // number var eleUnion16 = unionTuple1["1"]; // string | number var eleUnion20 = unionTuple2[0]; // boolean var eleUnion21 = unionTuple2[1]; // string | number var eleUnion22 = unionTuple2[2]; // string | number | boolean var eleUnion23 = unionTuple2[idx0]; // string | number | boolean var eleUnion24 = unionTuple2[idx1]; // string | number | boolean var eleUnion25 = unionTuple2["0"]; // boolean var eleUnion26 = unionTuple2["1"]; // string | number type t1 = [string, number][0]; // string type t2 = [string, number][1]; // number type t3 = [string, number][-1]; // undefined
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/indexersInClassType.ts
TypeScript
class C { [x: number]: Date; [x: string]: Object; 1: Date; 'a': {} fn() { return this; } } var c = new C(); var r = c.fn(); var r2 = r[1]; var r3 = r.a
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferFromBindingPattern.ts
TypeScript
// @strict: true declare function f1<T extends string>(): T; declare function f2<T extends string>(): [T]; declare function f3<T extends string>(): { x: T }; let x1 = f1(); // string let [x2] = f2(); // string let { x: x3 } = f3(); // string // Repro from #30379 function foo<T = number>(): [T] { return [42 as any] } const [x] = foo(); // [number] // Repro from #35291 interface SelectProps<T, K> { selector?: (obj: T) => K; } type SelectResult<T, K> = [K, T]; interface Person { name: string; surname: string; } declare function selectJohn<K = Person>(props?: SelectProps<Person, K>): SelectResult<Person, K>; const [person] = selectJohn(); const [any, whatever] = selectJohn(); const john = selectJohn(); const [personAgain, nufinspecial] = john; // Repro from #35291 declare function makeTuple<T1>(arg: T1): [T1]; declare function stringy<T = string>(arg?: T): T; const isStringTuple = makeTuple(stringy()); // [string] const [isAny] = makeTuple(stringy()); // [string]
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferThis.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @filename: /a.js export class C { /** * @template T * @this {T} * @return {T} */ static a() { return this; } /** * @template T * @this {T} * @return {T} */ b() { return this; } } const a = C.a(); a; // typeof C const c = new C(); const b = c.b(); b; // C
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferThisType.ts
TypeScript
declare function f<T>(g: (this: T) => void): T declare function h(this: number): void; f(h) // works with infer types as well type Check<T> = T extends (this: infer U, ...args: any[]) => any ? string : unknown; type r1 = Check<(this: number) => void>; // should be string type This<T> = T extends (this: infer U, ...args: any[]) => any ? U : unknown; type r2 = This<(this: number) => void>; // should be number
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferTypes2.ts
TypeScript
// @strict: true // @declaration: true // Repros from #22755 export declare function foo<T>(obj: T): T extends () => infer P ? P : never; export function bar<T>(obj: T) { return foo(obj); } export type BadNested<T> = { x: T extends number ? T : string }; export declare function foo2<T>(obj: T): T extends { [K in keyof BadNested<infer P>]: BadNested<infer P>[K] } ? P : never; export function bar2<T>(obj: T) { return foo2(obj); } // Repros from #31099 type Weird = any extends infer U ? U : never; type AlsoWeird = unknown extends infer U ? U : never; const a: Weird = null; const b: string = a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferTypesInvalidExtendsDeclaration.ts
TypeScript
// @declaration: true type Test<T> = T extends infer A extends B ? number : string;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferTypesWithExtends1.ts
TypeScript
// @strict: true // @declaration: true // infer to tuple element type X1<T extends any[]> = T extends [infer U extends string] ? ["string", U] : T extends [infer U extends number] ? ["number", U] : never; type X1_T1 = X1<["a"]>; // ["string", "a"] type X1_T2 = X1<[1]>; // ["number", 1] type X1_T3 = X1<[object]>; // never // infer to argument type X2<T extends (...args: any[]) => void> = T extends (a: infer U extends string) => void ? ["string", U] : T extends (a: infer U extends number) => void ? ["number", U] : never; type X2_T1 = X2<(a: "a") => void>; // ["string", "a"] type X2_T2 = X2<(a: 1) => void>; // ["number", 1] type X2_T3 = X2<(a: object) => void>; // never // infer to return type type X3<T extends (...args: any[]) => any> = T extends (...args: any[]) => (infer U extends string) ? ["string", U] : T extends (...args: any[]) => (infer U extends number) ? ["number", U] : never; type X3_T1 = X3<() => "a">; // ["string", "a"] type X3_T2 = X3<() => 1>; // ["number", 1] type X3_T3 = X3<() => object>; // never // infer to instance type type X4<T extends new (...args: any[]) => any> = T extends new (...args: any[]) => (infer U extends { a: string }) ? ["string", U] : T extends new (...args: any[]) => (infer U extends { a: number }) ? ["number", U] : never; type X4_T1 = X4<new () => { a: "a" }>; // ["string", { a: "a" }] type X4_T2 = X4<new () => { a: 1 }>; // ["number", { a: 1 }] type X4_T3 = X4<new () => { a: object }>; // never // infer to type argument type X5<T> = T extends Promise<infer U extends string> ? ["string", U] : T extends Promise<infer U extends number> ? ["number", U] : never; type X5_T1 = X5<Promise<"a" | "b">>; // ["string", "a" | "b"] type X5_T2 = X5<Promise<1 | 2>>; // ["number", 1 | 2] type X5_T3 = X5<Promise<1n | 2n>>; // never // infer to property type type X6<T> = T extends { a: infer U extends string } ? ["string", U] : T extends { a: infer U extends number } ? ["number", U] : never; type X6_T1 = X6<{ a: "a" }>; // ["string", "a"] type X6_T2 = X6<{ a: 1 }>; // ["number", 1] type X6_T3 = X6<{ a: object }>; // never // infer twice with same constraint type X7<T> = T extends { a: infer U extends string, b: infer U extends string } ? ["string", U] : T extends { a: infer U extends number, b: infer U extends number } ? ["number", U] : never; type X7_T1 = X7<{ a: "a", b: "b" }>; // ["string", "a" | "b"] type X7_T2 = X7<{ a: 1, b: 2 }>; // ["number", 1 | 2] type X7_T3 = X7<{ a: object, b: object }>; // never type X7_T4 = X7<{ a: "a", b: 1 }>; // never // infer twice with missing second constraint (same behavior as class/interface) type X8<T> = T extends { a: infer U extends string, b: infer U } ? ["string", U] : T extends { a: infer U extends number, b: infer U } ? ["number", U] : never; type X8_T1 = X8<{ a: "a", b: "b" }>; // ["string", "a" | "b"] type X8_T2 = X8<{ a: 1, b: 2 }>; // ["number", 1 | 2] type X8_T3 = X8<{ a: object, b: object }>; // never type X8_T4 = X8<{ a: "a", b: 1 }>; // never // infer twice with missing first constraint (same behavior as class/interface) type X9<T> = T extends { a: infer U, b: infer U extends string } ? ["string", U] : T extends { a: infer U, b: infer U extends number } ? ["number", U] : never; type X9_T1 = X9<{ a: "a", b: "b" }>; // ["string", "a" | "b"] type X9_T2 = X9<{ a: 1, b: 2 }>; // ["number", 1 | 2] type X9_T3 = X9<{ a: object, b: object }>; // never type X9_T4 = X9<{ a: "a", b: 1 }>; // never // Speculative lookahead for `infer T extends U ?` type X10<T> = T extends (infer U extends number ? 1 : 0) ? 1 : 0; // ok, parsed as conditional type X10_Y1<T> = X10<T extends number ? 1 : 0>; type X10_T1_T1 = X10_Y1<number>; type X11<T> = T extends ((infer U) extends number ? 1 : 0) ? 1 : 0; // ok, parsed as conditional type X12<T> = T extends (infer U extends number) ? 1 : 0; // ok, parsed as `infer..extends` (no trailing `?`) type X13<T> = T extends infer U extends number ? 1 : 0; // ok, parsed as `infer..extends` (conditional types not allowed in 'extends type') type X14<T> = T extends keyof infer U extends number ? 1 : 0; // ok, parsed as `infer..extends` (precedence wouldn't have parsed the `?` as part of a type operator) type X15<T> = T extends { [P in infer U extends keyof T ? 1 : 0]: 1; } ? 1 : 0; // ok, parsed as conditional type X16<T> = T extends { [P in infer U extends keyof T]: 1; } ? 1 : 0; // ok, parsed as `infer..extends` (no trailing `?`) type X17<T> = T extends { [P in keyof T as infer U extends P ? 1 : 0]: 1; } ? 1 : 0; // ok, parsed as conditional type X18<T> = T extends { [P in keyof T as infer U extends P]: 1; } ? 1 : 0; // ok, parsed as `infer..extends` (no trailing `?`) type X19<T extends string | number> = T extends (infer U extends number) ? [T, U] : never; type X19_T1 = X19<"a">; // never type X19_T2 = X19<1>; // [1, 1] type X19_T3 = X19<1 | "a">; // [1, 1] type X20<T> = T extends (infer U extends number) ? T extends (infer V extends U) ? [T, U, V] : never : never; type X20_T1 = X20<1 | "a">; // [1, 1, 1] type X21<T, N extends number> = T extends (infer U extends N) ? [T, U] : never; type X21_T1 = X21<1, 1>; // [1, 1] type X21_T2 = X21<1 | "a", 1>; // [1, 1] type X21_T3 = X21<1 | 2, 1>; // [1, 1] type X21_T4 = X21<1 | 2, 2 | 3>; // [2, 2] type X21_T5 = X21<1 | 2, 3>; // never // from mongoose type IfEquals<X, Y, A, B> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B; declare const x1: <T>() => (T extends infer U extends number ? 1 : 0); function f1() { return x1; } type ExpectNumber<T extends number> = T; declare const x2: <T>() => (T extends ExpectNumber<infer U> ? 1 : 0); function f2() { return x2; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferTypesWithExtends2.ts
TypeScript
// @strict: true // infer twice with different constraints (same behavior as class/interface) type X1<T> = T extends { a: infer U extends string, b: infer U extends number } ? U : never; // infer cannot reference type params in same 'extends' clause type X2<T> = T extends { a: infer U, b: infer V extends U } ? [U, V] : never;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferingFromAny.ts
TypeScript
// @allowJs: true // @noEmit: true // @fileName: a.ts var a: any; var t: [any, any]; declare function f1<T>(t: T): T declare function f2<T>(t: T[]): T; declare function f3<T, U>(t: [T, U]): [T, U]; declare function f4<T>(x: { bar: T; baz: T }): T; declare function f5<T>(x: (a: T) => void): T; declare function f6<T>(x: new (a: T) => {}): T; declare function f7<T>(x: (a: any) => a is T): T; declare function f8<T>(x: () => T): T; declare function f9<T>(x: new () => T): T; declare function f10<T>(x: { [x: string]: T }): T; declare function f11<T>(x: { [x: number]: T }): T; declare function f12<T, U>(x: T | U): [T, U]; declare function f13<T, U>(x: T & U): [T, U]; declare function f14<T, U>(x: { a: T | U, b: U & T }): [T, U]; interface I<T> { } declare function f15<T>(x: I<T>): T; declare function f16<T>(x: Partial<T>): T; declare function f17<T, K>(x: {[P in keyof T]: K}): T; declare function f18<T, K extends keyof T>(x: {[P in K]: T[P]}): T; declare function f19<T, K extends keyof T>(k: K, x: T[K]): T; // @fileName: a.js var a = f1(a); var a = f2(a); var t = f3(a); var a = f4(a); var a = f5(a); var a = f6(a); var a = f7(a); var a = f8(a); var a = f9(a); var a = f10(a); var a = f11(a); var t = f12(a); var t = f13(a); var t = f14(a); var a = f15(a); var a = f16(a); var a = f17(a); var a = f18(a); var a = f19(a, a);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments.ts
TypeScript
// @outFile: output.js // @allowJs: true // @checkJs: true // @noImplicitAny: true // @strictNullChecks: true // @filename: a.js class C { constructor() { if (Math.random()) { this.inConstructor = 0; } else { this.inConstructor = "string" } this.inMultiple = 0; } method() { if (Math.random()) { this.inMethod = 0; this.inMethodNullable = null; } else { this.inMethod = "string" this.inMethodNullable = undefined; } this.inMultiple = "string"; this.inMultipleMethods = "string"; var action = () => { if (Math.random()) { this.inNestedArrowFunction = 0; } else { this.inNestedArrowFunction = "string" } }; } get() { if (Math.random()) { this.inGetter = 0; } else { this.inGetter = "string" } this.inMultiple = false; this.inMultipleMethods = false; } set() { if (Math.random()) { this.inSetter = 0; } else { this.inSetter = "string" } } prop = () => { if (Math.random()) { this.inPropertyDeclaration = 0; } else { this.inPropertyDeclaration = "string" } } static method() { if (Math.random()) { this.inStaticMethod = 0; } else { this.inStaticMethod = "string" } var action = () => { if (Math.random()) { this.inStaticNestedArrowFunction = 0; } else { this.inStaticNestedArrowFunction = "string" } }; } static get() { if (Math.random()) { this.inStaticGetter = 0; } else { this.inStaticGetter = "string" } } static set() { if (Math.random()) { this.inStaticSetter = 0; } else { this.inStaticSetter = "string" } } static prop = () => { if (Math.random()) { this.inStaticPropertyDeclaration = 0; } else { this.inStaticPropertyDeclaration = "string" } } } // @filename: b.ts var c = new C(); var stringOrNumber: string | number; var stringOrNumber = c.inConstructor; var stringOrNumberOrUndefined: string | number | undefined; var stringOrNumberOrUndefined = c.inMethod; var stringOrNumberOrUndefined = c.inGetter; var stringOrNumberOrUndefined = c.inSetter; var stringOrNumberOrUndefined = c.inPropertyDeclaration; var stringOrNumberOrUndefined = c.inNestedArrowFunction var stringOrNumberOrBoolean: string | number | boolean; var number: number; var number = c.inMultiple; var stringOrBooleanOrUndefined : string | boolean | undefined; var stringOrBooleanOrUndefined = c.inMultipleMethods; var any: any; var any = c.inMethodNullable; var stringOrNumberOrUndefined = C.inStaticMethod; var stringOrNumberOrUndefined = C.inStaticGetter; var stringOrNumberOrUndefined = C.inStaticSetter; var stringOrNumberOrUndefined = C.inStaticPropertyDeclaration; var stringOrNumberOrUndefined = C.inStaticNestedArrowFunction;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments2.ts
TypeScript
// @checkJs: true // @noEmit: true // @filename: a.js OOOrder.prototype.m = function () { this.p = 1 } function OOOrder() { this.x = 1 }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments3.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @strictNullChecks: true // @Filename: a.js class Base { constructor() { this.p = 1 } } class Derived extends Base { m() { this.p = 1 } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments4.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @strictNullChecks: true // @Filename: a.js class Base { m() { this.p = 1 } } class Derived extends Base { m() { // should be OK, and p should have type number | undefined from its base this.p = 1 } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments5.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @strictNullChecks: true // @Filename: a.js class Base { m() { this.p = 1 } } class Derived extends Base { constructor() { super(); // should be OK, and p should have type number from this assignment this.p = 1 } test() { return this.p } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments6.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @strictNullChecks: true // @Filename: inferringClassMembersFromAssignments6.js function Foonly() { var self = this self.x = 1 self.m = function() { console.log(self.x) } } Foonly.prototype.mreal = function() { var self = this self.y = 2 } const foo = new Foonly() foo.x foo.y foo.m()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments7.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @strictNullChecks: true // @Filename: inferringClassMembersFromAssignments7.js class C { constructor() { var self = this self.x = 1 self.m = function() { console.log(self.x) } } mreal() { var self = this self.y = 2 } } const c = new C() c.x c.y c.m()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassMembersFromAssignments8.ts
TypeScript
// no inference in TS files, even for `this` aliases: var app = function() { var _this = this; _this.swap = function() { } } var a = new app() a
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inferringClassStaticMembersFromAssignments.ts
TypeScript
// @noEmit: true // @allowJs: true // @filename: a.js export class C1 { } C1.staticProp = 0; export function F1() { } F1.staticProp = 0; export var C2 = class { }; C2.staticProp = 0; export let F2 = function () { }; F2.staticProp = 0; //@filename: global.js class C3 { } C3.staticProp = 0; function F3() { } F3.staticProp = 0; var C4 = class { }; C4.staticProp = 0; let F4 = function () { }; F4.staticProp = 0; // @filename: b.ts import * as a from "./a"; var n: number; var n = a.C1.staticProp; var n = a.C2.staticProp; var n = a.F1.staticProp; var n = a.F2.staticProp; var n = C3.staticProp; var n = C4.staticProp; var n = F3.staticProp; var n = F4.staticProp;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/infiniteExpansionThroughInstantiation.ts
TypeScript
// instantiating a derived type can cause an infinitely expanding type reference to be generated interface List<T> { data: T; next: List<T>; owner: OwnerList<T>; } // will have an owner property that is an infinitely expanding type reference interface OwnerList<U> extends List<List<U>> { name: string; } var list: List<string>; var ownerList: OwnerList<string>; list = ownerList; function other<T>(x: T) { var list: List<T>; var ownerList: OwnerList<T>; list = ownerList; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/infiniteExpansionThroughInstantiation2.ts
TypeScript
// instantiating a derived type can cause an infinitely expanding type reference to be generated // which could be used in an assignment check for constraint satisfaction interface AA<T extends AA<T>> // now an error due to referencing type parameter in constraint { x: T } interface BB extends AA<AA<BB>> { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/infiniteExpansionThroughTypeInference.ts
TypeScript
interface G<T> { x: G<G<T>> // infinitely expanding type reference y: T } function ff<T>(g: G<T>): void { ff(g) // when infering T here we need to make sure to not descend into the structure of G<T> infinitely }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/initializationOrdering1.ts
TypeScript
// @target: esnext, es2021, es2022 // @useDefineForClassFields: true, false class Helper { create(): boolean { return true } } export class Broken { constructor(readonly facade: Helper) { console.log(this.bug) } bug = this.facade.create() } new Broken(new Helper)
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/initializerReferencingConstructorLocals.ts
TypeScript
// Initializer expressions for instance member variables are evaluated in the scope of the class constructor body but are not permitted to reference parameters or local variables of the constructor. class C { a = z; // error b: typeof z; // error c = this.z; // error d: typeof this.z; // error constructor(x) { z = 1; } } class D<T> { a = z; // error b: typeof z; // error c = this.z; // error d: typeof this.z; // error constructor(x: T) { z = 1; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/initializerReferencingConstructorParameters.ts
TypeScript
// Initializer expressions for instance member variables are evaluated in the scope of the class constructor body but are not permitted to reference parameters or local variables of the constructor. class C { a = x; // error b: typeof x; // error constructor(x) { } } class D { a = x; // error b: typeof x; // error constructor(public x) { } } class E { a = this.x; // ok b: typeof this.x; // ok constructor(public x) { } } class F<T> { a = this.x; // ok b = x; // error constructor(public x: T) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/initializersWidened.ts
TypeScript
// these are widened to any at the point of assignment var x1 = null; var y1 = undefined; var z1 = void 0; // these are not widened var x2: null; var y2: undefined; var x3: null = null; var y3: undefined = undefined; var z3: undefined = void 0; // widen only when all constituents of union are widening var x4 = null || null; var y4 = undefined || undefined; var z4 = void 0 || void 0; var x5 = null || x2; var y5 = undefined || y2; var z5 = void 0 || y2;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inlineJsxAndJsxFragPragma.tsx
TypeScript (TSX)
// @jsx: react // @noUnusedLocals: true // @filename: renderer.d.ts declare global { namespace JSX { interface IntrinsicElements { [e: string]: any; } } } export function h(): void; export function jsx(): void; export function Fragment(): void; // @filename: preacty.tsx /** * @jsx h * @jsxFrag Fragment */ import {h, Fragment} from "./renderer"; <><div></div></> // @filename: snabbdomy.tsx /* @jsx jsx */ /* @jsxfrag null */ import {jsx} from "./renderer"; <><span></span></> // @filename: preacty-only-fragment.tsx /** * @jsx h * @jsxFrag Fragment */ import {h, Fragment} from "./renderer"; <></> // @filename: snabbdomy-only-fragment.tsx /* @jsx jsx */ /* @jsxfrag null */ import {jsx} from "./renderer"; <></> // @filename: preacty-only-fragment-no-jsx.tsx /** * @jsx h * @jsxFrag Fragment */ import {Fragment} from "./renderer"; <></> // @filename: snabbdomy-only-fragment-no-jsx.tsx /* @jsx jsx */ /* @jsxfrag null */ import {} from "./renderer"; <></> // @filename: preacty-no-fragment.tsx /** * @jsx h * @jsxFrag Fragment */ import {h, Fragment} from "./renderer"; <div></div> // @filename: snabbdomy-no-fragment.tsx /* @jsx jsx */ /* @jsxfrag null */ import {jsx} from "./renderer"; <div></div> // @filename: preacty-only-component.tsx /** * @jsx h */ import {h} from "./renderer"; function Component() { return null; } <Component />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inlineJsxAndJsxFragPragmaOverridesCompilerOptions.tsx
TypeScript (TSX)
// @jsx: react // @jsxFactory: createElement // @jsxFragmentFactory: Fragment // @filename: react.d.ts declare global { namespace JSX { interface IntrinsicElements { [e: string]: any; } } } export function createElement(): void; export function Fragment(): void; // @filename: preact.d.ts export function h(): void; export function Frag(): void; // @filename: snabbdom.d.ts export function h(): void; // @filename: reacty.tsx import {createElement, Fragment} from "./react"; <><span></span></> // @filename: preacty.tsx /** * @jsx h * @jsxFrag Frag */ import {h, Frag} from "./preact"; <><div></div></> // @filename: snabbdomy.tsx /** * @jsx h * @jsxfrag null */ import {h} from "./snabbdom"; <><div></div></> // @filename: mix-n-match.tsx /* @jsx h */ /* @jsxFrag Fragment */ import {h} from "./preact"; import {Fragment} from "./react"; <><span></span></>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inlineJsxFactoryDeclarations.tsx
TypeScript (TSX)
// @jsx: react // @filename: renderer.d.ts declare global { namespace JSX { interface IntrinsicElements { [e: string]: any; } } } export function dom(): void; export function otherdom(): void; export function createElement(): void; export { dom as default }; // @filename: otherreacty.tsx /** @jsx React.createElement */ import * as React from "./renderer"; <h></h> // @filename: other.tsx /** @jsx h */ import { dom as h } from "./renderer" export const prerendered = <h></h>; // @filename: othernoalias.tsx /** @jsx otherdom */ import { otherdom } from "./renderer" export const prerendered2 = <h></h>; // @filename: reacty.tsx import React from "./renderer" export const prerendered3 = <h></h>; // @filename: index.tsx /** @jsx dom */ import { dom } from "./renderer" <h></h> export * from "./other"; export * from "./othernoalias"; export * from "./reacty";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inlineJsxFactoryDeclarationsLocalTypes.tsx
TypeScript (TSX)
// @jsx: react // @filename: renderer.d.ts export namespace dom { namespace JSX { interface IntrinsicElements { [e: string]: {}; } interface Element { __domBrand: void; props: { children?: Element[]; }; } interface ElementClass extends Element { render(): Element; } interface ElementAttributesProperty { props: any; } interface ElementChildrenAttribute { children: any; } } } export function dom(): dom.JSX.Element; // @filename: renderer2.d.ts export namespace predom { namespace JSX { interface IntrinsicElements { [e: string]: {}; } interface Element { __predomBrand: void; props: { children?: Element[]; }; } interface ElementClass extends Element { render(): Element; } interface ElementAttributesProperty { props: any; } interface ElementChildrenAttribute { children: any; } } } export function predom(): predom.JSX.Element; // @filename: component.tsx /** @jsx predom */ import { predom } from "./renderer2" export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Element[]}) => <p>{props.x} + {props.y} = {props.x + props.y}{...this.props.children}</p>; export class MyClass implements predom.JSX.Element { __predomBrand!: void; constructor(public props: {x: number, y: number, children?: predom.JSX.Element[]}) {} render() { return <p> {this.props.x} + {this.props.y} = {this.props.x + this.props.y} {...this.props.children} </p>; } } export const tree = <MySFC x={1} y={2}><MyClass x={3} y={4} /><MyClass x={5} y={6} /></MySFC> export default <h></h> // @filename: index.tsx /** @jsx dom */ import { dom } from "./renderer" import prerendered, {MySFC, MyClass, tree} from "./component"; let elem = prerendered; elem = <h></h>; // Expect assignability error here const DOMSFC = (props: {x: number, y: number, children?: dom.JSX.Element[]}) => <p>{props.x} + {props.y} = {props.x + props.y}{props.children}</p>; class DOMClass implements dom.JSX.Element { __domBrand!: void; constructor(public props: {x: number, y: number, children?: dom.JSX.Element[]}) {} render() { return <p>{this.props.x} + {this.props.y} = {this.props.x + this.props.y}{...this.props.children}</p>; } } // Should work, everything is a DOM element const _tree = <DOMSFC x={1} y={2}><DOMClass x={3} y={4} /><DOMClass x={5} y={6} /></DOMSFC> // Should fail, no dom elements const _brokenTree = <MySFC x={1} y={2}><MyClass x={3} y={4} /><MyClass x={5} y={6} /></MySFC> // Should fail, nondom isn't allowed as children of dom const _brokenTree2 = <DOMSFC x={1} y={2}>{tree}{tree}</DOMSFC>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inlineJsxFactoryLocalTypeGlobalFallback.tsx
TypeScript (TSX)
// @jsx: react // @filename: renderer.d.ts declare global { namespace JSX { interface IntrinsicElements { [e: string]: {}; } interface Element { __domBrand: void; children: Element[]; props: {}; } interface ElementAttributesProperty { props: any; } interface ElementChildrenAttribute { children: any; } } } export function dom(): JSX.Element; // @filename: renderer2.d.ts export namespace predom { namespace JSX { interface IntrinsicElements { [e: string]: {}; } interface Element { __predomBrand: void; children: Element[]; props: {}; } interface ElementAttributesProperty { props: any; } interface ElementChildrenAttribute { children: any; } } } export function predom(): predom.JSX.Element; // @filename: component.tsx /** @jsx predom */ import { predom } from "./renderer2" export default <h></h> // @filename: index.tsx /** @jsx dom */ import { dom } from "./renderer" import prerendered from "./component"; let elem = prerendered; elem = <h></h>; // Expect assignability error here
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inlineJsxFactoryOverridesCompilerOption.tsx
TypeScript (TSX)
// @jsx: react // @jsxFactory: p // @filename: renderer.d.ts declare global { namespace JSX { interface IntrinsicElements { [e: string]: any; } } } export function dom(): void; export { dom as p }; // @filename: reacty.tsx /** @jsx dom */ import {dom} from "./renderer"; <h></h> // @filename: index.tsx import { p } from "./renderer"; <h></h>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/inlineJsxFactoryWithFragmentIsError.tsx
TypeScript (TSX)
// @jsx: react // @filename: renderer.d.ts declare global { namespace JSX { interface IntrinsicElements { [e: string]: any; } } } export function dom(): void; export function createElement(): void; // @filename: reacty.tsx /** @jsx React.createElement */ import * as React from "./renderer"; <><h></h></> // @filename: index.tsx /** @jsx dom */ import { dom } from "./renderer"; <><h></h></>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/innerTypeParameterShadowingOuterOne.ts
TypeScript
// inner type parameters shadow outer ones of the same name // no errors expected function f<T extends Date>() { function g<T extends Number>() { var x: T; x.toFixed(); } var x: T; x.getDate(); } function f2<T extends Date, U extends Date>() { function g<T extends Number, U extends Number>() { var x: U; x.toFixed(); } var x: U; x.getDate(); } //function f2<T extends Date, U extends T>() { // function g<T extends Number, U extends T>() { // var x: U; // x.toFixed(); // } // var x: U; // x.getDate(); //}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/innerTypeParameterShadowingOuterOne2.ts
TypeScript
// inner type parameters shadow outer ones of the same name // no errors expected class C<T extends Date> { g<T extends Number>() { var x: T; x.toFixed(); } h() { var x: T; x.getDate(); } } class C2<T extends Date, U extends Date> { g<T extends Number, U extends Number>() { var x: U; x.toFixed(); } h() { var x: U; x.getDate(); } } //class C2<T extends Date, U extends T> { // g<T extends Number, U extends T>() { // var x: U; // x.toFixed(); // } // h() { // var x: U; // x.getDate(); // } //}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceMemberAssignsToClassPrototype.ts
TypeScript
class C { foo() { C.prototype.foo = () => { } } bar(x: number): number { C.prototype.bar = () => { } // error C.prototype.bar = (x) => x; // ok C.prototype.bar = (x: number) => 1; // ok return 1; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceMemberInitialization.ts
TypeScript
class C { x = 1; } var c = new C(); c.x = 3; var c2 = new C(); var r = c.x === c2.x; // #31792 class MyMap<K, V> { constructor(private readonly Map_: { new<K, V>(): any }) {} private readonly store = new this.Map_<K, V>(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceMemberWithComputedPropertyName.ts
TypeScript
// https://github.com/microsoft/TypeScript/issues/30953 "use strict"; const x = 1; class C { [x] = true; constructor() { const { a, b } = { a: 1, b: 2 }; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceMemberWithComputedPropertyName2.ts
TypeScript
// https://github.com/microsoft/TypeScript/issues/33857 // @useDefineForClassFields: true // @target: es2015 "use strict"; const x = 1; class C { [x]: string; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instancePropertiesInheritedIntoClassType.ts
TypeScript
module NonGeneric { class C { x: string; get y() { return 1; } set y(v) { } fn() { return this; } constructor(public a: number, private b: number) { } } class D extends C { e: string; } var d = new D(1, 2); var r = d.fn(); var r2 = r.x; var r3 = r.y; r.y = 4; var r6 = d.y(); // error } module Generic { class C<T, U> { x: T; get y() { return null; } set y(v: U) { } fn() { return this; } constructor(public a: T, private b: U) { } } class D<T, U> extends C<T, U> { e: T; } var d = new D(1, ''); var r = d.fn(); var r2 = r.x; var r3 = r.y; r.y = ''; var r6 = d.y(); // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instancePropertyInClassType.ts
TypeScript
module NonGeneric { class C { x: string; get y() { return 1; } set y(v) { } fn() { return this; } constructor(public a: number, private b: number) { } } var c = new C(1, 2); var r = c.fn(); var r2 = r.x; var r3 = r.y; r.y = 4; var r6 = c.y(); // error } module Generic { class C<T,U> { x: T; get y() { return null; } set y(v: U) { } fn() { return this; } constructor(public a: T, private b: U) { } } var c = new C(1, ''); var r = c.fn(); var r2 = r.x; var r3 = r.y; r.y = ''; var r6 = c.y(); // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithAny.ts
TypeScript
var a: any; var r: boolean = a instanceof a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithInvalidOperands.es2015.ts
TypeScript
// @target: es2015 // @lib: es2015 class C { foo() { } } var x: any; // invalid left operand // the left operand is required to be of type Any, an object type, or a type parameter type var a1: number; var a2: boolean; var a3: string; var a4: void; var ra1 = a1 instanceof x; var ra2 = a2 instanceof x; var ra3 = a3 instanceof x; var ra4 = a4 instanceof x; var ra5 = 0 instanceof x; var ra6 = true instanceof x; var ra7 = '' instanceof x; var ra8 = null instanceof x; var ra9 = undefined instanceof x; // invalid right operand // the right operand to be of type Any or a subtype of the 'Function' interface type var b1: number; var b2: boolean; var b3: string; var b4: void; var o1: {}; var o2: Object; var o3: C; var rb1 = x instanceof b1; var rb2 = x instanceof b2; var rb3 = x instanceof b3; var rb4 = x instanceof b4; var rb5 = x instanceof 0; var rb6 = x instanceof true; var rb7 = x instanceof ''; var rb8 = x instanceof o1; var rb9 = x instanceof o2; var rb10 = x instanceof o3; // both operands are invalid var rc1 = '' instanceof {}; // @@hasInstance restricts LHS var o4: {[Symbol.hasInstance](value: { x: number }): boolean;}; var o5: { y: string }; var ra10 = o5 instanceof o4; // invalid @@hasInstance method return type on RHS var o6: {[Symbol.hasInstance](value: unknown): number;}; var rb11 = x instanceof o6;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithInvalidOperands.ts
TypeScript
class C { foo() { } } var x: any; // invalid left operand // the left operand is required to be of type Any, an object type, or a type parameter type var a1: number; var a2: boolean; var a3: string; var a4: void; var ra1 = a1 instanceof x; var ra2 = a2 instanceof x; var ra3 = a3 instanceof x; var ra4 = a4 instanceof x; var ra5 = 0 instanceof x; var ra6 = true instanceof x; var ra7 = '' instanceof x; var ra8 = null instanceof x; var ra9 = undefined instanceof x; // invalid right operand // the right operand to be of type Any or a subtype of the 'Function' interface type var b1: number; var b2: boolean; var b3: string; var b4: void; var o1: {}; var o2: Object; var o3: C; var rb1 = x instanceof b1; var rb2 = x instanceof b2; var rb3 = x instanceof b3; var rb4 = x instanceof b4; var rb5 = x instanceof 0; var rb6 = x instanceof true; var rb7 = x instanceof ''; var rb8 = x instanceof o1; var rb9 = x instanceof o2; var rb10 = x instanceof o3; // both operands are invalid var rc1 = '' instanceof {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithInvalidStaticToString.ts
TypeScript
declare class StaticToString { static toString(): void; } function foo(staticToString: StaticToString) { return staticToString instanceof StaticToString; } declare class StaticToNumber { static toNumber(): void; } function bar(staticToNumber: StaticToNumber) { return staticToNumber instanceof StaticToNumber; } declare class NormalToString { toString(): void; } function baz(normal: NormalToString) { return normal instanceof NormalToString; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithLHSIsObject.ts
TypeScript
class C { } var x1: any; var x2: Function; var a: {}; var b: Object; var c: C; var d: string | C; var r1 = a instanceof x1; var r2 = b instanceof x2; var r3 = c instanceof x1; var r4 = d instanceof x1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithLHSIsTypeParameter.ts
TypeScript
function foo<T>(t: T) { var x: any; var r = t instanceof x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithRHSHasSymbolHasInstance.ts
TypeScript
// @target: es2015 // @lib: es2015 interface Point { x: number, y: number } interface Point3D { x: number, y: number, z: number } interface Point3D2 extends Point { z: number } interface Line { start: Point, end: Point } declare var rhs0: { [Symbol.hasInstance](value: unknown): boolean; }; declare var rhs1: { [Symbol.hasInstance](value: any): boolean; }; declare var rhs2: { [Symbol.hasInstance](value: any): value is Point; }; declare var rhs3: { [Symbol.hasInstance](value: Point | Line): value is Point; }; declare var rhs4: { [Symbol.hasInstance](value: Point | Line): value is Line; }; declare var rhs5: { [Symbol.hasInstance](value: Point | Point3D | Line): value is Point3D; }; declare var rhs6: { [Symbol.hasInstance](value: Point3D | Line): value is Point3D; }; declare class Rhs7 { static [Symbol.hasInstance](value: unknown): boolean; } declare class Rhs8 { static [Symbol.hasInstance](value: any): boolean; } declare class Rhs9 { static [Symbol.hasInstance](value: any): value is Point; } declare class Rhs10 { static [Symbol.hasInstance](value: Point | Line): value is Point; } declare class Rhs11 { static [Symbol.hasInstance](value: Point | Line): value is Line; } declare class Rhs12 { static [Symbol.hasInstance](value: Point | Point3D | Line): value is Point3D; } declare class Rhs13 { static [Symbol.hasInstance](value: Point3D | Line): value is Point3D; } declare var lhs0: any; declare var lhs1: object; declare var lhs2: Point | Point3D | Line; declare var lhs3: Point3D | Line; declare var lhs4: Point | Point3D2 | Line; lhs0 instanceof rhs0 && lhs0; lhs0 instanceof rhs1 && lhs0; lhs0 instanceof rhs2 && lhs0; lhs0 instanceof rhs3 && lhs0; lhs0 instanceof rhs4 && lhs0; lhs0 instanceof rhs5 && lhs0; lhs0 instanceof rhs6 && lhs0; lhs0 instanceof Rhs7 && lhs0; lhs0 instanceof Rhs8 && lhs0; lhs0 instanceof Rhs9 && lhs0; lhs0 instanceof Rhs10 && lhs0; lhs0 instanceof Rhs11 && lhs0; lhs0 instanceof Rhs12 && lhs0; lhs0 instanceof Rhs13 && lhs0; lhs1 instanceof rhs0 && lhs1; lhs1 instanceof rhs1 && lhs1; lhs1 instanceof rhs2 && lhs1; lhs1 instanceof Rhs7 && lhs1; lhs1 instanceof Rhs8 && lhs1; lhs1 instanceof Rhs9 && lhs1; lhs2 instanceof rhs0 && lhs2; lhs2 instanceof rhs1 && lhs2; lhs2 instanceof rhs2 && lhs2; lhs2 instanceof rhs3 && lhs2; lhs2 instanceof rhs4 && lhs2; lhs2 instanceof rhs5 && lhs2; lhs2 instanceof Rhs7 && lhs2; lhs2 instanceof Rhs8 && lhs2; lhs2 instanceof Rhs9 && lhs2; lhs2 instanceof Rhs10 && lhs2; lhs2 instanceof Rhs11 && lhs2; lhs2 instanceof Rhs12 && lhs2; lhs3 instanceof rhs0 && lhs3; lhs3 instanceof rhs1 && lhs3; lhs3 instanceof rhs2 && lhs3; lhs3 instanceof rhs3 && lhs3; lhs3 instanceof rhs4 && lhs3; lhs3 instanceof rhs5 && lhs3; lhs3 instanceof rhs6 && lhs3; lhs3 instanceof Rhs7 && lhs3; lhs3 instanceof Rhs8 && lhs3; lhs3 instanceof Rhs9 && lhs3; lhs3 instanceof Rhs10 && lhs3; lhs3 instanceof Rhs11 && lhs3; lhs3 instanceof Rhs12 && lhs3; lhs3 instanceof Rhs13 && lhs3; lhs4 instanceof rhs0 && lhs4; lhs4 instanceof rhs1 && lhs4; lhs4 instanceof rhs2 && lhs4; lhs4 instanceof rhs3 && lhs4; lhs4 instanceof rhs4 && lhs4; lhs4 instanceof rhs5 && lhs4; lhs4 instanceof Rhs7 && lhs4; lhs4 instanceof Rhs8 && lhs4; lhs4 instanceof Rhs9 && lhs4; lhs4 instanceof Rhs10 && lhs4; lhs4 instanceof Rhs11 && lhs4; lhs4 instanceof Rhs12 && lhs4; declare class A { #x: number; // approximation of `getInstanceType` behavior, with one caveat: the checker versions unions the return types of // all construct signatures, but we have no way of extracting individual construct signatures from a type. static [Symbol.hasInstance]<T>(this: T, value: unknown): value is ( T extends globalThis.Function ? T extends { readonly prototype: infer U } ? boolean extends (U extends never ? true : false) ? // <- tests whether 'U' is 'any' T extends (abstract new (...args: any) => infer V) ? V : {} : U : never : never ); } declare class B extends A { #y: number; } declare const obj: unknown; if (obj instanceof A) { obj; // A } if (obj instanceof B) { obj; // B } // intersections // https://github.com/microsoft/TypeScript/issues/56536 interface HasInstanceOf { [Symbol.hasInstance](x: unknown): boolean } type Rhs14 = HasInstanceOf & object; declare const rhs14: Rhs14; lhs0 instanceof rhs14 && lhs0; // unions interface HasInstanceOf1 { [Symbol.hasInstance](x: unknown): x is Point } interface HasInstanceOf2 { [Symbol.hasInstance](x: unknown): x is Line } type Rhs15 = HasInstanceOf1 | HasInstanceOf2; declare const rhs15: Rhs15; lhs0 instanceof rhs15 && lhs0;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instanceofOperatorWithRHSIsSubtypeOfFunction.ts
TypeScript
interface I extends Function { } var x: any; var f1: Function; var f2: I; var f3: { (): void }; var f4: { new (): number }; var r1 = x instanceof f1; var r2 = x instanceof f2; var r3 = x instanceof f3; var r4 = x instanceof f4; var r5 = x instanceof null; var r6 = x instanceof undefined;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instantiateGenericClassWithWrongNumberOfTypeArguments.ts
TypeScript
// it is always an error to provide a type argument list whose count does not match the type parameter list // both of these attempts to construct a type is an error class C<T> { x: T; } var c = new C<number, number>(); class D<T, U> { x: T y: U } // BUG 794238 var d = new D<number>();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instantiateGenericClassWithZeroTypeArguments.ts
TypeScript
// no errors expected when instantiating a generic type with no type arguments provided class C<T> { x: T; } var c = new C(); class D<T, U> { x: T y: U } var d = new D();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instantiateNonGenericTypeWithTypeArguments.ts
TypeScript
// it is an error to provide type arguments to a non-generic call // all of these are errors class C { x: string; } var c = new C<number>(); function Foo(): void { } var r = new Foo<number>(); var f: { (): void }; var r2 = new f<number>(); var a: any; // BUG 790977 var r2 = new a<number>();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instantiateTemplateTagTypeParameterOnVariableStatement.ts
TypeScript
// @checkJs: true // @allowJs: true // @declaration: true // @emitDeclarationOnly: true // @filename: instantiateTemplateTagTypeParameterOnVariableStatement.js /** * @template T * @param {T} a * @returns {(b: T) => T} */ const seq = a => b => b; const text1 = "hello"; const text2 = "world"; /** @type {string} */ var text3 = seq(text1)(text2);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/instantiatedModule.ts
TypeScript
// adding the var makes this an instantiated module module M { export interface Point { x: number; y: number } export var Point = 1; } // primary expression var m: typeof M; var m = M; var a1: number; var a1 = M.Point; var a1 = m.Point; var p1: { x: number; y: number; } var p1: M.Point; // making the point a class instead of an interface // makes this an instantiated mmodule module M2 { export class Point { x: number; y: number; static Origin(): Point { return { x: 0, y: 0 }; } } } var m2: typeof M2; var m2 = M2; // static side of the class var a2: typeof M2.Point; var a2 = m2.Point; var a2 = M2.Point; var o: M2.Point = a2.Origin(); var p2: { x: number; y: number } var p2: M2.Point; var p2 = new m2.Point(); var p2 = new M2.Point(); module M3 { export enum Color { Blue, Red } } var m3: typeof M3; var m3 = M3; var a3: typeof M3.Color; var a3 = m3.Color; var a3 = M3.Color; var blue: M3.Color = a3.Blue; var p3: M3.Color; var p3 = M3.Color.Red; var p3 = m3.Color.Blue;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceDoesNotDependOnBaseTypes.ts
TypeScript
var x: StringTree; if (typeof x !== "string") { x.push(""); x.push([""]); } type StringTree = string | StringTreeArray; interface StringTreeArray extends Array<StringTree> { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendingClass.ts
TypeScript
class Foo { x: string; y() { } get Z() { return 1; } [x: string]: Object; } interface I extends Foo { } var i: I; var r1 = i.x; var r2 = i.y(); var r3 = i.Z; var f: Foo = i; i = f;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendingClassWithPrivates.ts
TypeScript
class Foo { private x: string; } interface I extends Foo { // error x: string; } interface I2 extends Foo { y: string; } var i: I2; var r = i.y; var r2 = i.x; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendingClassWithPrivates2.ts
TypeScript
class Foo { private x: string; } class Bar { private x: string; } interface I3 extends Foo, Bar { // error } interface I4 extends Foo, Bar { // error x: string; } class Baz { private y: string; } interface I5 extends Foo, Baz { z: string; } var i: I5; var r: string = i.z; var r2 = i.x; // error var r3 = i.y; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendingClassWithProtecteds.ts
TypeScript
class Foo { protected x: string; } interface I extends Foo { // error x: string; } interface I2 extends Foo { y: string; } var i: I2; var r = i.y; var r2 = i.x; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendingClassWithProtecteds2.ts
TypeScript
class Foo { protected x: string; } class Bar { protected x: string; } interface I3 extends Foo, Bar { // error } interface I4 extends Foo, Bar { // error x: string; } class Baz { protected y: string; } interface I5 extends Foo, Baz { z: string; } var i: I5; var r: string = i.z; var r2 = i.x; // error var r3 = i.y; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendingOptionalChain.ts
TypeScript
namespace Foo { export class Bar {} } interface C1 extends Foo?.Bar {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendsObjectIntersection.ts
TypeScript
// @strictNullChecks: true type T1 = { a: number }; type T2 = T1 & { b: number }; type T3 = () => void; type T4 = new () => { a: number }; type T5 = number[]; type T6 = [string, number]; type T7 = { [P in 'a' | 'b' | 'c']: string }; interface I1 extends T1 { x: string } interface I2 extends T2 { x: string } interface I3 extends T3 { x: string } interface I4 extends T4 { x: string } interface I5 extends T5 { x: string } interface I6 extends T6 { x: string } interface I7 extends T7 { x: string } type Constructor<T> = new () => T; declare function Constructor<T>(): Constructor<T>; class C1 extends Constructor<I1>() { x: string } class C2 extends Constructor<I2>() { x: string } class C3 extends Constructor<I3>() { x: string } class C4 extends Constructor<I4>() { x: string } class C5 extends Constructor<I5>() { x: string } class C6 extends Constructor<I6>() { x: string } class C7 extends Constructor<I7>() { x: string } declare function fx(x: string): string; declare class CX { a: number } declare enum EX { A, B, C } declare namespace NX { export const a = 1 } type T10 = typeof fx; type T11 = typeof CX; type T12 = typeof EX; type T13 = typeof NX; interface I10 extends T10 { x: string } interface I11 extends T11 { x: string } interface I12 extends T12 { x: string } interface I13 extends T13 { x: string } type Identifiable<T> = { _id: string } & T; interface I20 extends Partial<T1> { x: string } interface I21 extends Readonly<T1> { x: string } interface I22 extends Identifiable<T1> { x: string } interface I23 extends Identifiable<T1 & { b: number}> { x: string } class C20 extends Constructor<Partial<T1>>() { x: string } class C21 extends Constructor<Readonly<T1>>() { x: string } class C22 extends Constructor<Identifiable<T1>>() { x: string } class C23 extends Constructor<Identifiable<T1 & { b: number}>>() { x: string }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceExtendsObjectIntersectionErrors.ts
TypeScript
// @strictNullChecks: true type T1 = { a: number }; type T2 = T1 & { b: number }; type T3 = number[]; type T4 = [string, number]; type T5 = { [P in 'a' | 'b' | 'c']: string }; interface I1 extends T1 { a: string } interface I2 extends T2 { b: string } interface I3 extends T3 { length: string } interface I4 extends T4 { 0: number } interface I5 extends T5 { c: number } type Constructor<T> = new () => T; declare function Constructor<T>(): Constructor<T>; class C1 extends Constructor<T1>() { a: string } class C2 extends Constructor<T2>() { b: string } class C3 extends Constructor<T3>() { length: string } class C4 extends Constructor<T4>() { 0: number } class C5 extends Constructor<T5>() { c: number } declare class CX { static a: string } declare enum EX { A, B, C } declare namespace NX { export const a = "hello" } type TCX = typeof CX; type TEX = typeof EX; type TNX = typeof NX; interface I10 extends TCX { a: number } interface I11 extends TEX { C: string } interface I12 extends TNX { a: number } interface I14 extends TCX { [x: string]: number } interface I15 extends TEX { [x: string]: number } interface I16 extends TNX { [x: string]: number } type Identifiable<T> = { _id: string } & T; interface I20 extends Partial<T1> { a: string } interface I21 extends Readonly<T1> { a: string } interface I22 extends Identifiable<T1> { a: string } interface I23 extends Identifiable<T1 & { b: number}> { a: string } type U = { a: number } | { b: string }; interface I30 extends U { x: string } interface I31<T> extends T { x: string }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceThatHidesBaseProperty.ts
TypeScript
interface Base { x: { a: number }; } interface Derived extends Base { x: { a: number; b: number; }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceThatHidesBaseProperty2.ts
TypeScript
interface Base { x: { a: number }; } interface Derived extends Base { // error x: { a: string; }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceThatIndirectlyInheritsFromItself.ts
TypeScript
interface Base extends Derived2 { // error x: string; } interface Derived extends Base { y: string; } interface Derived2 extends Derived { z: string; } module Generic { interface Base<T> extends Derived2<T> { // error x: string; } interface Derived<T> extends Base<T> { y: string; } interface Derived2<T> extends Derived<T> { z: string; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithCallAndConstructSignature.ts
TypeScript
interface Foo { (): number; new (): any; } var f: Foo; var r = f(); var r2 = new f();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithCallSignaturesThatHidesBaseSignature.ts
TypeScript
interface Foo { (): { a: number }; } interface Derived extends Foo { (): { a: number; b: number }; } var d: Derived; var r = d();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithCallSignaturesThatHidesBaseSignature2.ts
TypeScript
interface Foo { (): { a: number; b: number }; } interface Derived extends Foo { // error (): { a: number }; } var d: Derived; var r = d();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithConstructSignaturesThatHidesBaseSignature.ts
TypeScript
interface Foo { new (): { a: number }; } interface Derived extends Foo { new (): { a: number; b: number }; } var d: Derived; var r = new d();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithConstructSignaturesThatHidesBaseSignature2.ts
TypeScript
interface Foo { new (): { a: number; b: number }; } interface Derived extends Foo { new (): { a: number }; // constructors not checked for conformance like a call signature is } var d: Derived; var r = new d();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithMultipleBaseTypes.ts
TypeScript
// an interface may have multiple bases with properties of the same name as long as the interface's implementation satisfies all base type versions interface Base1 { x: { a: string; } } interface Base2 { x: { b: string; } } interface Derived extends Base1, Base2 { x: { a: string; b: string; } } interface Derived2 extends Base1, Base2 { // error x: { a: string; b: number; } } module Generic { interface Base1<T> { x: { a: T; } } interface Base2<T> { x: { b: T; } } interface Derived<T> extends Base1<string>, Base2<number> { x: { a: string; b: number; } } interface Derived2<T, U> extends Base1<T>, Base2<U> { x: { a: T; b: U; } } interface Derived3<T> extends Base1<number>, Base2<number> { } // error interface Derived4<T> extends Base1<number>, Base2<number> { // error x: { a: T; b: T; } } interface Derived5<T> extends Base1<T>, Base2<T> { // error x: T; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithMultipleBaseTypes2.ts
TypeScript
interface Base { x: { a?: string; b: string; } } interface Base2 { x: { b: string; c?: number; } } interface Derived extends Base, Base2 { x: { b: string } } interface Derived2 extends Base, Base2 { // error x: { a: number; b: string } } interface Derived3 extends Base, Base2 { x: { a: string; b: string } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithOverloadedCallAndConstructSignatures.ts
TypeScript
interface Foo { (): number; (x: string): number; new (): any; new (x: string): Object; } var f: Foo; var r1 = f(); var r2 = f(''); var r3 = new f(); var r4 = new f('');
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithPropertyOfEveryType.ts
TypeScript
class C { foo: string; } function f1() { } module M { export var y = 1; } enum E { A } interface Foo { a: number; b: string; c: boolean; d: any; e: void; f: number[]; g: Object; h: (x: number) => number; i: <T>(x: T) => T; j: Foo; k: C; l: typeof f1; m: typeof M; n: {}; o: E; } var a: Foo = { a: 1, b: '', c: true, d: {}, e: null , f: [1], g: {}, h: (x: number) => 1, i: <T>(x: T) => x, j: <Foo>null, k: new C(), l: f1, m: M, n: {}, o: E.A }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithPropertyThatIsPrivateInBaseType.ts
TypeScript
class Base { private x: number; } interface Foo extends Base { // error x: number; } class Base2<T> { private x: T; } interface Foo2<T> extends Base2<T> { // error x: number; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithPropertyThatIsPrivateInBaseType2.ts
TypeScript
class Base { private x() {} } interface Foo extends Base { // error x(): any; } class Base2<T> { private x() { } } interface Foo2<T> extends Base2<T> { // error x(): any; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithSpecializedCallAndConstructSignatures.ts
TypeScript
interface Foo { (x: 'a'): number; (x: string): any; new (x: 'a'): any; new (x: string): Object; } var f: Foo; var r = f('a'); var r2 = f('A'); var r3 = new f('a'); var r4 = new f('A');
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithStringIndexerHidingBaseTypeIndexer.ts
TypeScript
interface Base { [x: string]: { a: number } x: { a: number; b: number; } } interface Derived extends Base { [x: string]: { a: number; b: number }; // error y: { a: number; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithStringIndexerHidingBaseTypeIndexer2.ts
TypeScript
interface Base { [x: number]: { a: number; b: number } x: { a: number; b: number; } } interface Derived extends Base { [x: string]: { a: number }; y: { a: number; } // error 1: { a: number; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfaceWithStringIndexerHidingBaseTypeIndexer3.ts
TypeScript
interface Base { [x: number]: { a: number } 1: { a: number; b: number; } } interface Derived extends Base { [x: number]: { a: number; b: number }; // error 2: { a: number; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/interfacesWithPredefinedTypesAsNames.ts
TypeScript
interface any { } interface number { } interface string { } interface boolean { } interface void {} interface unknown {} interface never {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionAndUnionTypes.ts
TypeScript
interface A { a: string } interface B { b: string } interface C { c: string } interface D { d: string } var a: A; var b: B; var c: C; var d: D; var anb: A & B; var aob: A | B; var cnd: C & D; var cod: C | D; var x: A & B | C & D; var y: (A | B) & (C | D); a = anb; // Ok b = anb; // Ok anb = a; anb = b; x = anb; // Ok x = aob; x = cnd; // Ok x = cod; anb = x; aob = x; cnd = x; cod = x; y = anb; y = aob; y = cnd; y = cod; anb = y; aob = y; // Ok cnd = y; cod = y; // Ok
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionAsWeakTypeSource.ts
TypeScript
interface X { x: string } interface Y { y: number } interface Z { z?: boolean } type XY = X & Y; const xy: XY = {x: 'x', y: 10}; const z1: Z = xy; // error, {xy} doesn't overlap with {z} interface ViewStyle { view: number styleMedia: string } type Brand<T> = number & { __brand: T } declare function create<T extends { [s: string]: ViewStyle }>(styles: T): { [P in keyof T]: Brand<T[P]> }; const wrapped = create({ first: { view: 0, styleMedia: "???" } }); const vs: ViewStyle = wrapped.first // error, first is a branded number
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionIncludingPropFromGlobalAugmentation.ts
TypeScript
// @strict: true // @noEmit: true // repro from https://github.com/microsoft/TypeScript/issues/54345 interface Test1 { toString: null | 'string'; } type Test2 = Test1 & { optional?: unknown }; declare const source: Test1; const target: Test2 = { ...source }; const toString = target.toString; const hasOwn = target.hasOwnProperty; // not an own member but it should still be accessible export {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionMemberOfUnionNarrowsCorrectly.ts
TypeScript
export type U = { kind?: 'A', a: string } | { kind?: 'B' } & { b: string }; type Ex<T, U> = T extends U ? T : never; declare let x: Ex<U, { kind?: 'A' }> x.a
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionNarrowing.ts
TypeScript
// @strict: true // Repros from #43130 function f1<T>(x: T & string | T & undefined) { if (x) { x; // Should narrow to T & string } } function f2<T>(x: T & string | T & undefined) { if (x !== undefined) { x; // Should narrow to T & string } else { x; // Should narrow to T & undefined } } function f3<T>(x: T & string | T & number) { if (typeof x === "string") { x; // Should narrow to T & string } else { x; // Should narrow to T & number } } function f4<T>(x: T & 1 | T & 2) { switch (x) { case 1: x; break; // T & 1 case 2: x; break; // T & 2 default: x; // Should narrow to never } } function f5<T extends string | number>(x: T & number) { const t1 = x === "hello"; // Should be an error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionOfUnionNarrowing.ts
TypeScript
// @strict: true interface X { a?: { aProp: string }; b?: { bProp: string }; } type AorB = { a: object; b: undefined } | { a: undefined; b: object }; declare const q: X & AorB; if (q.a !== undefined) { q.a.aProp; } else { // q.b is previously incorrectly inferred as potentially undefined q.b.bProp; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionOfUnionOfUnitTypes.ts
TypeScript
// @strict const enum E { A, B, C, D, E, F } let x0: ('a' | 'b' | 'c') & ('a' | 'b' | 'c'); // 'a' | 'b' | 'c' let x1: ('a' | 'b' | 'c') & ('b' | 'c' | 'd'); // 'b' | 'c' let x2: ('a' | 'b' | 'c') & ('c' | 'd' | 'e'); // 'c' let x3: ('a' | 'b' | 'c') & ('d' | 'e' | 'f'); // never let x4: ('a' | 'b' | 'c') & ('b' | 'c' | 'd') & ('c' | 'd' | 'e'); // 'c' let x5: ('a' | 'b' | 'c') & ('b' | 'c' | 'd') & ('c' | 'd' | 'e') & ('d' | 'e' | 'f'); // never let y0: (0 | 1 | 2) & (0 | 1 | 2); // 0 | 1 | 2 let y1: (0 | 1 | 2) & (1 | 2 | 3); // 1 | 2 let y2: (0 | 1 | 2) & (2 | 3 | 4); // 2 let y3: (0 | 1 | 2) & (3 | 4 | 5); // never let y4: (0 | 1 | 2) & (1 | 2 | 3) & (2 | 3 | 4); // 2 let y5: (0 | 1 | 2) & (1 | 2 | 3) & (2 | 3 | 4) & (3 | 4 | 5); // never let z0: (E.A | E.B | E.C) & (E.A | E.B | E.C); // E.A | E.B | E.C let z1: (E.A | E.B | E.C) & (E.B | E.C | E.D); // E.B | E.C let z2: (E.A | E.B | E.C) & (E.C | E.D | E.E); // E.C let z3: (E.A | E.B | E.C) & (E.D | E.E | E.F); // never let z4: (E.A | E.B | E.C) & (E.B | E.C | E.D) & (E.C | E.D | E.E); // E.C let z5: (E.A | E.B | E.C) & (E.B | E.C | E.D) & (E.C | E.D | E.E) & (E.D | E.E | E.F); // never
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionReduction.ts
TypeScript
// @strict: false declare const sym1: unique symbol; declare const sym2: unique symbol; type T1 = string & 'a'; // 'a' type T2 = 'a' & string & 'b'; // never type T3 = number & 10; // 10 type T4 = 10 & number & 20; // never type T5 = symbol & typeof sym1; // typeof sym1 type T6 = typeof sym1 & symbol & typeof sym2; // never type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never type T10 = string & ('a' | 'b'); // 'a' | 'b' type T11 = (string | number) & ('a' | 10); // 'a' | 10 type N1 = 'a' & 'b'; type N2 = { a: string } & null; type N3 = { a: string } & undefined; type N4 = string & number; type N5 = number & object; type N6 = symbol & string; type N7 = void & string; type X = { x: string }; type X1 = X | 'a' & 'b'; type X2 = X | { a: string } & null; type X3 = X | { a: string } & undefined; type X4 = X | string & number; type X5 = X | number & object; type X6 = X | symbol & string; type X7 = X | void & string; type A = { kind: 'a', foo: string }; type B = { kind: 'b', foo: number }; type C = { kind: 'c', foo: number }; declare let ab: A & B; ab.kind; // Error declare let x: A | (B & C); // A let a: A = x; type AB = A & B; // never type BC = B & C; // never type U1 = Partial<A & B>; // never type U2 = Readonly<A & B>; // never type U3 = (A & B)['kind']; // never type U4 = A & B | B & C; // never type U5 = A | B & C; // A type K1 = keyof (A & B); // string | number | symbol type K2 = keyof A | keyof B; // 'kind' | 'foo' type Merge1<T, U> = { [P in keyof (T & U)]: P extends keyof T ? T[P] : U[P & keyof U] } type Merge2<T, U> = { [P in keyof T | keyof U]: P extends keyof T ? T[P] : U[P & keyof U] } type M1 = { a: 1, b: 2 } & { a: 2, c: 3 }; // never type M2 = Merge1<{ a: 1, b: 2 }, { a: 2, c: 3 }>; // {} type M3 = Merge2<{ a: 1, b: 2 }, { a: 2, c: 3 }>; // { a: 1, b: 2, c: 3 } type D = { kind: 'd', foo: unknown }; type E = { kind: 'e', foo: unknown }; declare function f10<T>(x: { foo: T }): T; declare let a1: A | D; declare let a2: A | D & E; let r1 = f10(a1); // unknown let r2 = f10(a2); // string // Repro from #31663 const x1 = { a: 'foo', b: 42 }; const x2 = { a: 'foo', b: true }; declare let k: 'a' | 'b'; x1[k] = 'bar' as any; // Error x2[k] = 'bar' as any; // Error const enum Tag1 {} const enum Tag2 {} declare let s1: string & Tag1; declare let s2: string & Tag2; declare let t1: string & Tag1 | undefined; declare let t2: string & Tag2 | undefined; s1 = s2; s2 = s1; t1 = t2; t2 = t1; // Repro from #36736 const f1 = (t: "a" | ("b" & "c")): "a" => t; type Container<Type extends string> = { type: Type; } const f2 = (t: Container<"a"> | (Container<"b"> & Container<"c">)): Container<"a"> => t; const f3 = (t: Container<"a"> | (Container<"b"> & { dataB: boolean } & Container<"a">)): Container<"a"> => t; const f4 = (t: number | (Container<"b"> & { dataB: boolean } & Container<"a">)): number => t; // Repro from #38549 interface A2 { kind: "A"; a: number; } interface B2 { kind: "B"; b: number; } declare const shouldBeB: (A2 | B2) & B2; const b: B2 = shouldBeB; // works function inGeneric<T extends A2 | B2>(alsoShouldBeB: T & B2) { const b: B2 = alsoShouldBeB; } // Repro from #38542 interface ABI { kind: 'a' | 'b'; } declare class CA { kind: 'a'; a: string; x: number }; declare class CB { kind: 'b'; b: string; y: number }; function bar<T extends CA | CB>(x: T & CA) { let ab: ABI = x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionReductionStrict.ts
TypeScript
// @strict: true declare const sym1: unique symbol; declare const sym2: unique symbol; type T1 = string & 'a'; // 'a' type T2 = 'a' & string & 'b'; // never type T3 = number & 10; // 10 type T4 = 10 & number & 20; // never type T5 = symbol & typeof sym1; // typeof sym1 type T6 = typeof sym1 & symbol & typeof sym2; // never type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never type T10 = string & ('a' | 'b'); // 'a' | 'b' type T11 = (string | number) & ('a' | 10); // 'a' | 10 type N1 = 'a' & 'b'; type N2 = { a: string } & null; type N3 = { a: string } & undefined; type N4 = string & number; type N5 = number & object; type N6 = symbol & string; type N7 = void & string; type X = { x: string }; type X1 = X | 'a' & 'b'; type X2 = X | { a: string } & null; type X3 = X | { a: string } & undefined; type X4 = X | string & number; type X5 = X | number & object; type X6 = X | symbol & string; type X7 = X | void & string; type A = { kind: 'a', foo: string }; type B = { kind: 'b', foo: number }; type C = { kind: 'c', foo: number }; declare let ab: A & B; ab.kind; // Error declare let x: A | (B & C); // A let a: A = x; type AB = A & B; // never type BC = B & C; // never type U1 = Partial<A & B>; // never type U2 = Readonly<A & B>; // never type U3 = (A & B)['kind']; // never type U4 = A & B | B & C; // never type U5 = A | B & C; // A type K1 = keyof (A & B); // string | number | symbol type K2 = keyof A | keyof B; // 'kind' | 'foo' type Merge1<T, U> = { [P in keyof (T & U)]: P extends keyof T ? T[P] : U[P & keyof U] } type Merge2<T, U> = { [P in keyof T | keyof U]: P extends keyof T ? T[P] : U[P & keyof U] } type M1 = { a: 1, b: 2 } & { a: 2, c: 3 }; // never type M2 = Merge1<{ a: 1, b: 2 }, { a: 2, c: 3 }>; // {} type M3 = Merge2<{ a: 1, b: 2 }, { a: 2, c: 3 }>; // { a: 1, b: 2, c: 3 } // Repro from #31663 const x1 = { a: 'foo', b: 42 }; const x2 = { a: 'foo', b: true }; declare let k: 'a' | 'b'; x1[k] = 'bar' as any; // Error x2[k] = 'bar' as any; // Error const enum Tag1 {} const enum Tag2 {} declare let s1: string & Tag1; declare let s2: string & Tag2; declare let t1: string & Tag1 | undefined; declare let t2: string & Tag2 | undefined; s1 = s2; s2 = s1; t1 = t2; t2 = t1; // Repro from #36736 const f1 = (t: "a" | ("b" & "c")): "a" => t; type Container<Type extends string> = { type: Type; } const f2 = (t: Container<"a"> | (Container<"b"> & Container<"c">)): Container<"a"> => t; const f3 = (t: Container<"a"> | (Container<"b"> & { dataB: boolean } & Container<"a">)): Container<"a"> => t; const f4 = (t: number | (Container<"b"> & { dataB: boolean } & Container<"a">)): number => t;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionThisTypes.ts
TypeScript
interface Thing1 { a: number; self(): this; } interface Thing2 { b: number; me(): this; } type Thing3 = Thing1 & Thing2; type Thing4 = Thing3 & string[]; function f1(t: Thing3) { t = t.self(); t = t.me().self().me(); } interface Thing5 extends Thing4 { c: string; } function f2(t: Thing5) { t = t.self(); t = t.me().self().me(); } interface Component { extend<T>(props: T): this & T; } interface Label extends Component { title: string; } function test(label: Label) { const extended = label.extend({ id: 67 }).extend({ tag: "hello" }); extended.id; // Ok extended.tag; // Ok }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionTypeAssignment.ts
TypeScript
var a: { a: string }; var b: { b: string }; var x: { a: string, b: string }; var y: { a: string } & { b: string }; a = x; a = y; x = a; // Error y = a; // Error b = x; b = y; x = b; // Error y = b; // Error x = y; y = x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionTypeEquivalence.ts
TypeScript
interface A { a: string } interface B { b: string } interface C { c: string } // A & B is equivalent to B & A. var y: A & B; var y : B & A; // AB & C is equivalent to A & BC, where AB is A & B and BC is B & C. var z : A & B & C; var z : (A & B) & C; var z : A & (B & C); var ab : A & B; var bc : B & C; var z1: typeof ab & C; var z1: A & typeof bc;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionTypeInference.ts
TypeScript
function extend<T, U>(obj1: T, obj2: U): T & U { var result: T & U; obj1 = result; obj2 = result; result = obj1; // Error result = obj2; // Error return result; } var x = extend({ a: "hello" }, { b: 42 }); var s = x.a; var n = x.b; interface A<T> { a: T; } interface B<U> { b: U; } function foo<T, U>(obj: A<T> & B<U>): T | U { return undefined; } var z = foo({ a: "hello", b: 42 }); var z: string | number;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionTypeInference2.ts
TypeScript
declare function f<T>(x: { prop: T }): T; declare const a: { prop: string } & { prop: number }; declare const b: { prop: string & number }; f(a); // never f(b); // never // Repro from #18354 declare function f2<T, Key extends keyof T>(obj: {[K in keyof T]: T[K]}, key: Key): T[Key]; declare const obj: { a: string } & { b: string }; f2(obj, 'a'); f2(obj, 'b');
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionTypeInference3.ts
TypeScript
// @strict: true // @target: es2015 // Repro from #19682 type Nominal<Kind extends string, Type> = Type & { [Symbol.species]: Kind; }; type A = Nominal<'A', string>; declare const a: Set<A>; declare const b: Set<A>; const c1 = Array.from(a).concat(Array.from(b)); // Simpler repro declare function from<T>(): T[]; const c2: ReadonlyArray<A> = from();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/intersectionTypeMembers.ts
TypeScript
// An intersection type has those members that are present in any of its constituent types, // with types that are intersections of the respective members in the constituent types interface A { a: string } interface B { b: string } interface C { c: string } var abc: A & B & C; abc.a = "hello"; abc.b = "hello"; abc.c = "hello"; interface X { x: A } interface Y { x: B } interface Z { x: C } var xyz: X & Y & Z; xyz.x.a = "hello"; xyz.x.b = "hello"; xyz.x.c = "hello"; type F1 = (x: string) => string; type F2 = (x: number) => number; var f: F1 & F2; var s = f("hello"); var n = f(42); interface D { nested: { doublyNested: { d: string; }, different: { e: number } }; } interface E { nested: { doublyNested: { f: string; }, other: {g: number } }; } const de: D & E = { nested: { doublyNested: { d: 'yes', f: 'no' }, different: { e: 12 }, other: { g: 101 } } } // Additional test case with >2 doubly nested members so fix for #31441 is tested w/ excess props interface F { nested: { doublyNested: { g: string; } } } interface G { nested: { doublyNested: { h: string; } } } const defg: D & E & F & G = { nested: { doublyNested: { d: 'yes', f: 'no', g: 'ok', h: 'affirmative' }, different: { e: 12 }, other: { g: 101 } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University