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/libReferenceDeclarationEmitBundle.ts
TypeScript
// @target: esnext // @module: amd // @lib: esnext // @declaration: true // @outFile: bundle.js // @filename: file1.ts /// <reference lib="dom" preserve="true" /> export declare const elem: HTMLElement; // @filename: file2.ts /// <reference lib="dom" preserve="true" /> export {} declare const elem: HTMLElement;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/libReferenceNoLib.ts
TypeScript
// @target: esnext // @module: commonjs // @noLib: true // @declaration: true // Test that passing noLib disables <reference lib> resolution. // @filename: fakelib.ts interface Object { } interface Array<T> { } interface String { } interface Boolean { } interface Number { } interface Function { } interface RegExp { } interface IArguments { } // @filename: file1.ts /// <reference lib="dom" /> export declare interface HTMLElement { field: string; } export const elem: HTMLElement = { field: 'a' };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/libReferenceNoLibBundle.ts
TypeScript
// @target: esnext // @module: amd // @noLib: true // @declaration: true // @outFile: bundle.js // Test that passing noLib disables <reference lib> resolution. // @filename: fakelib.ts interface Object { } interface Array<T> { } interface String { } interface Boolean { } interface Number { } interface Function { } interface RegExp { } interface IArguments { } // @filename: file1.ts /// <reference lib="dom" /> export declare interface HTMLElement { field: string; } export const elem: HTMLElement = { field: 'a' };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-1.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @typeRoots: /src/types // We can find typings in the ./types folder // @filename: /src/types/jquery/index.d.ts declare var $: { foo(): void }; // @filename: /src/consumer.ts /// <reference types="jquery" /> $.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-14.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @types: jquery // @typeRoots: /a/types // @currentDirectory: /a // @filename: /a/types/jquery/index.d.ts declare var $: { foo(): void }; // @filename: /a/b/consumer.ts $.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-15.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @types: jquery // @typeRoots: /a/types // @filename: /a/types/jquery/index.d.ts declare var $: { foo(): void }; // @filename: /a/types/jquery2/index.d.ts declare var $2: { foo(): void }; // @filename: /a/b/consumer.ts $.foo(); // should OK $2.foo(); // should error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-3.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @currentDirectory: /src // Secondary references are possible // @filename: /src/node_modules/jquery/index.d.ts declare var $: { foo(): void }; // @filename: /src/consumer.ts /// <reference types="jquery" /> $.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-4.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @typeRoots: /src // @currentDirectory: test // Secondary references may be duplicated if they agree in content // @filename: /node_modules/foo/index.d.ts /// <reference types="alpha" /> declare var foo: any; // @filename: /node_modules/foo/node_modules/alpha/index.d.ts declare var alpha: any; // @filename: /node_modules/bar/index.d.ts /// <reference types="alpha" /> declare var bar: any; // @filename: /node_modules/bar/node_modules/alpha/index.d.ts declare var alpha: any; // @filename: /src/root.ts /// <reference types="foo" /> /// <reference types="bar" />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-5.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @currentDirectory: / // @typeRoots: types // Secondary references may not be duplicated if they disagree in content // @filename: /node_modules/foo/index.d.ts /// <reference types="alpha" /> declare var foo: any; // @filename: /node_modules/foo/node_modules/alpha/index.d.ts declare var alpha: any; // @filename: /node_modules/bar/index.d.ts /// <reference types="alpha" /> declare var bar: any; // @filename: /node_modules/bar/node_modules/alpha/index.d.ts declare var alpha: {}; // @filename: /src/root.ts /// <reference types="foo" /> /// <reference types="bar" />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-6.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @currentDirectory: / // The primary lookup folder is relative to tsconfig.json, if present // @filename: /node_modules/@types/alpha/index.d.ts declare var alpha: { a: string }; // @filename: /src/foo.ts /// <reference types="alpha" /> var x: string = alpha.a; // @filename: /tsconfig.json { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-7.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @currentDirectory: / // Secondary references are possible // @filename: /src/node_modules/jquery/index.d.ts declare var $: { foo(): void }; // @filename: /src/consumer.ts /// <reference types="jquery" /> $.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-8.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @typeRoots: /test/types // @currentDirectory: /test // Don't crash in circular library reference situations // @filename: /test/types/alpha/index.d.ts /// <reference types="beta" /> declare var alpha: { a: string }; // @filename: /test/types/beta/index.d.ts /// <reference types="alpha" /> declare var beta: { b: string }; // @filename: /test/foo.ts /// <reference types="alpha" /> /// <reference types="beta" /> var x: string = alpha.a + beta.b;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/library-reference-scoped-packages.ts
TypeScript
// @noImplicitReferences: true // @traceResolution: true // @typeRoots: types // @filename: /node_modules/@types/beep__boop/index.d.ts export const y = 0; // @filename: /a.ts /// <reference types="@beep/boop" />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/linkTagEmit1.ts
TypeScript
// @checkJs: true // @outdir: foo // @declaration: true // @filename: declarations.d.ts declare namespace NS { type R = number } // @filename: linkTagEmit1.js /** @typedef {number} N */ /** * @typedef {Object} D1 * @property {1} e Just link to {@link NS.R} this time * @property {1} m Wyatt Earp loved {@link N integers} I bet. */ /** @typedef {number} Z @see N {@link N} */ /** * @param {number} integer {@link Z} */ function computeCommonSourceDirectoryOfFilenames(integer) { return integer + 1 // pls pls pls } /** {@link https://hvad} */ var see3 = true /** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/literalTypeWidening.ts
TypeScript
// Widening vs. non-widening literal types function f1() { const c1 = "hello"; // Widening type "hello" let v1 = c1; // Type string const c2 = c1; // Widening type "hello" let v2 = c2; // Type string const c3: "hello" = "hello"; // Type "hello" let v3 = c3; // Type "hello" const c4: "hello" = c1; // Type "hello" let v4 = c4; // Type "hello" } function f2(cond: boolean) { const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar" const c2: "foo" | "bar" = c1; // "foo" | "bar" const c3 = cond ? c1 : c2; // "foo" | "bar" const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz" const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz" let v1 = c1; // string let v2 = c2; // "foo" | "bar" let v3 = c3; // "foo" | "bar" let v4 = c4; // string let v5 = c5; // "foo" | "bar" | "baz" } function f3() { const c1 = 123; // Widening type 123 let v1 = c1; // Type number const c2 = c1; // Widening type 123 let v2 = c2; // Type number const c3: 123 = 123; // Type 123 let v3 = c3; // Type 123 const c4: 123 = c1; // Type 123 let v4 = c4; // Type 123 } function f4(cond: boolean) { const c1 = cond ? 123 : 456; // widening 123 | widening 456 const c2: 123 | 456 = c1; // 123 | 456 const c3 = cond ? c1 : c2; // 123 | 456 const c4 = cond ? c3 : 789; // 123 | 456 | widening 789 const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789 let v1 = c1; // number let v2 = c2; // 123 | 456 let v3 = c3; // 123 | 456 let v4 = c4; // number let v5 = c5; // 123 | 456 | 789 } function f5() { const c1 = "foo"; let v1 = c1; const c2: "foo" = "foo"; let v2 = c2; const c3 = "foo" as "foo"; let v3 = c3; const c4 = <"foo">"foo"; let v4 = c4; } declare function widening<T>(x: T): T; declare function nonWidening<T extends string | number | symbol>(x: T): T; function f6(cond: boolean) { let x1 = widening('a'); let x2 = widening(10); let x3 = widening(cond ? 'a' : 10); let y1 = nonWidening('a'); let y2 = nonWidening(10); let y3 = nonWidening(cond ? 'a' : 10); } // Repro from #10898 type FAILURE = "FAILURE"; const FAILURE = "FAILURE"; type Result<T> = T | FAILURE; function doWork<T>(): Result<T> { return FAILURE; } function isSuccess<T>(result: Result<T>): result is T { return !isFailure(result); } function isFailure<T>(result: Result<T>): result is FAILURE { return result === FAILURE; } function increment(x: number): number { return x + 1; } let result = doWork<number>(); if (isSuccess(result)) { increment(result); } // Repro from #10898 type TestEvent = "onmouseover" | "onmouseout"; function onMouseOver(): TestEvent { return "onmouseover"; } let x = onMouseOver(); // Repro from #23649 export function Set<K extends string>(...keys: K[]): Record<K, true | undefined> { const result = {} as Record<K, true | undefined> keys.forEach(key => result[key] = true) return result } export function keys<K extends string, V>(obj: Record<K, V>): K[] { return Object.keys(obj) as K[] } type Obj = { code: LangCode } const langCodeSet = Set('fr', 'en', 'es', 'it', 'nl') export type LangCode = keyof typeof langCodeSet export const langCodes = keys(langCodeSet) const arr: Obj[] = langCodes.map(code => ({ code })) // Repro from #29081 function test<T extends { a: string, b: string }>(obj: T): T { let { a, ...rest } = obj; return { a: 'hello', ...rest } as T; } // Repro from #32169 declare function f<T>(x: T): NonNullable<T>; enum E { A, B } const a = f(E.A); const b: E.A = a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/literalTypes1.ts
TypeScript
// @strictNullChecks: true let zero: 0 = 0; let one: 1 = 1; let two: 2 = 2; let oneOrTwo: 1 | 2 = <1 | 2>1; function f1(x: 0 | 1 | 2) { switch (x) { case zero: x; break; case one: x; break; case two: x; break; default: x; } } function f2(x: 0 | 1 | 2) { switch (x) { case zero: x; break; case oneOrTwo: x; break; default: x; } } type Falsy = false | 0 | "" | null | undefined; function f3(x: Falsy) { if (x) { x; } else { x; } } function f4(x: 0 | 1 | true | string) { switch (x) { case 0: x; break; case 1: x; break; case "abc": case "def": x; break; case null: x; break; case undefined: x; break; default: x; } } function f5(x: string | number | boolean) { switch (x) { case "abc": x; break; case 0: case 1: x; break; case true: x; break; case "hello": case 123: x; break; default: x; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/literalTypes2.ts
TypeScript
enum E { A, B, C } let cond: boolean; function f1(p1 = 1, p2 = "abc", p3 = true, p4 = E.A) { var v1 = 1; var v2 = -123; var v3 = 3 + 4; var v4 = "abc"; var v5 = ""; var v6 = "abc" + "def"; var v7 = true; var v8 = E.A; let x1 = 1; let x2 = -123; let x3 = 3 + 4; let x4 = "abc"; let x5 = ""; let x6 = "abc" + "def"; let x7 = true; var x8 = E.A; const c1 = 1; const c2 = -123; const c3 = 3 + 4; const c4 = "abc"; const c5 = ""; const c6 = "abc" + "def"; const c7 = true; const c8 = E.A; } function f2(p1: 1 = 1, p2: "abc" = "abc", p3: true = true, p4: E.A = E.A) { var v1: 1 = 1; var v2: -123 = -123; var v3: "abc" = "abc"; var v4: true = true; var v5: E.A = E.A; let x1: 1 = 1; let x2: -123 = -123; let x3: "abc" = "abc"; let x4: true = true; let x5: E.A = E.A; } function f3() { const c1 = cond ? 1 : 2; const c2 = cond ? 1 : "two"; const c3 = cond ? E.A : cond ? true : 123; const c4 = cond ? "abc" : null; const c5 = cond ? 456 : undefined; const c6: { kind: 123 } = { kind: 123 }; const c7: [1 | 2, "foo" | "bar"] = [1, "bar"]; const c8 = cond ? c6 : cond ? c7 : "hello"; let x1 = c1; let x2 = c2; let x3 = c3; let x4 = c4; let x5 = c5; let x6 = c6; let x7 = c7; let x8 = c8; } class C1 { x1 = 1; x2 = -123; x3 = 3 + 4; x4 = "abc"; x5 = ""; x6 = "abc" + "def"; x7 = true; x8 = E.A; readonly c1 = 1; readonly c2 = -123; readonly c3 = 3 + 4; readonly c4 = "abc"; readonly c5 = ""; readonly c6 = "abc" + "def"; readonly c7 = true; readonly c8 = E.A; } function f4() { const c1 = { a: 1, b: "foo" }; const c2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" }; let x1 = { a: 1, b: "foo" }; let x2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" }; } function f5() { const c1 = [1, "foo"]; const c2: (1 | "foo")[] = [1, "foo"]; const c3: [1, "foo"] = [1, "foo"]; let x1 = [1, "foo"]; let x2: (1 | "foo")[] = [1, "foo"]; let x3: [1, "foo"] = [1, "foo"]; } function f6() { const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" }; let { x1 = true, x2 = 0, x3 = "foo" } = { x1: false, x2: 1, x3: "bar" }; } function f10() { return "hello"; } function f11() { return cond ? 1 : "two"; } function f12() { if (cond) { return 1; } else { return "two"; } } class C2 { foo() { return 0; } bar() { return cond ? 0 : 1; } } function f20() { const f1 = () => 0; const f2 = () => "hello"; const f3 = () => true; const f4 = () => E.C; const f5 = (): "foo" => "foo"; const f6: () => "foo" | "bar" = () => "bar"; const f7: (() => "foo") | (() => "bar") = () => "bar"; } declare function g1<T>(x: T): T; declare function g2<T>(x: T, y: T): T; declare function g3<T, U>(x: T, y: U): T | U; declare function g4<T>(x: T): T[]; declare function g5<T extends number>(x: T, y: T): T[]; declare function g6<T>(x: T[]): T; declare function g7<T>(x: T[]): T[]; declare function g8<T>(x: T, f: (p: T) => T): T; const a: (1 | 2)[] = [1, 2]; const x1 = g1(1); // Type 1 const x2 = g2(1, 1); // Type 1 const x3 = g2(1, 2); // Type 1 | 2 const x4 = g3(1, "two"); // Type 1 | "two" const x5 = g4(1); // Type number[] const x6 = g5(1, 2); // Type (1 | 2)[] const x7 = g6([1, 2]); // Type number const x8 = g6(a); // Type 1 | 2 const x9 = g7(a); // Type (1 | 2)[] const x10 = g8(1, x => x); // Type number const x11 = g8(1, x => x + 1); // Type number function makeArray<T>(x: T): T[] { return [x]; } function append<T>(a: T[], x: T): T[] { let result = a.slice(); result.push(x); return result; } type Bit = 0 | 1; let aa = makeArray<Bit>(0); aa = append(aa, 1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/literalTypes3.ts
TypeScript
// @strictNullChecks: true function f1(s: string) { if (s === "foo") { s; // "foo" } if (s === "foo" || s === "bar") { s; // "foo" | "bar" } } function f2(s: string) { switch (s) { case "foo": case "bar": s; // "foo" | "bar" case "baz": s; // "foo" | "bar" | "baz" break; default: s; // string } } function f3(s: string) { return s === "foo" || s === "bar" ? s : undefined; // "foo" | "bar" | undefined } function f4(x: number) { if (x === 1 || x === 2) { return x; // 1 | 2 } throw new Error(); } function f5(x: number, y: 1 | 2) { if (x === 0 || x === y) { x; // 0 | 1 | 2 } } function f6(x: number, y: 1 | 2) { if (y === x || 0 === x) { x; // 0 | 1 | 2 } } function f7(x: number | "foo" | "bar", y: 1 | 2 | string) { if (x === y) { x; // "foo" | "bar" | 1 | 2 } } function f8(x: number | "foo" | "bar") { switch (x) { case 1: case 2: x; // 1 | 2 break; case "foo": x; // "foo" break; default: x; // number | "bar" } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/literalTypesAndDestructuring.ts
TypeScript
// @strict: true declare let x: { a: 0 | 1 | undefined }; let { a: a1 } = x; let { a: a2 = 0 } = x; let { a: a3 = 2 } = x; let { a: a4 = 2 as const } = x; let b1 = x.a; let b2 = x.a ?? 0; let b3 = x.a ?? 2; let b4 = x.a ?? 2 as const; // Repro from #35693 interface Foo { bar: 'yo' | 'ha' | undefined; } let { bar = 'yo' } = {} as Foo; bar; // "yo" | "ha"
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/literalTypesAndTypeAssertions.ts
TypeScript
const obj = { a: "foo" as "foo", b: <"foo">"foo", c: "foo" }; let x1 = 1 as (0 | 1); let x2 = 1; let { a = "foo" } = { a: "foo" }; let { b = "foo" as "foo" } = { b: "bar" }; let { c = "foo" } = { c: "bar" as "bar" }; let { d = "foo" as "foo" } = { d: "bar" as "bar" };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/literalTypesWidenInParameterPosition.ts
TypeScript
class D { readonly noWiden = 1 constructor(readonly widen = 2) { this.noWiden = 5; // error this.widen = 6; // ok } } new D(7); // ok
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/localTypes1.ts
TypeScript
// @target: es5 function f1() { enum E { A, B, C } class C { x: E; } interface I { x: E; } type A = I[]; let a: A = [new C()]; a[0].x = E.B; return a; } function f2() { function g() { enum E { A, B, C } class C { x: E; } interface I { x: E; } type A = I[]; let a: A = [new C()]; a[0].x = E.B; return a; } return g(); } function f3(b: boolean) { if (true) { enum E { A, B, C } if (b) { class C { x: E; } interface I { x: E; } type A = I[]; let a: A = [new C()]; a[0].x = E.B; return a; } else { class A { x: E; } interface J { x: E; } type C = J[]; let c: C = [new A()]; c[0].x = E.B; return c; } } } function f5() { var z1 = function () { enum E { A, B, C } class C { x: E; } return new C(); } var z2 = () => { enum E { A, B, C } class C { x: E; } return new C(); } } class A { constructor() { enum E { A, B, C } class C { x: E; } } m() { enum E { A, B, C } class C { x: E; } return new C(); } get p() { enum E { A, B, C } class C { x: E; } return new C(); } } function f6() { class A { a: string; } function g() { class B extends A { b: string; } function h() { class C extends B { c: string; } var x = new C(); x.a = "a"; x.b = "b"; x.c = "c"; return x; } return h(); } return g(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/localTypes2.ts
TypeScript
function f1() { function f() { class C { constructor(public x: number, public y: number) { } } return C; } let C = f(); let v = new C(10, 20); let x = v.x; let y = v.y; } function f2() { function f(x: number) { class C { public x = x; constructor(public y: number) { } } return C; } let C = f(10); let v = new C(20); let x = v.x; let y = v.y; } function f3() { function f(x: number, y: number) { class C { public x = x; public y = y; } return C; } let C = f(10, 20); let v = new C(); let x = v.x; let y = v.y; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/localTypes3.ts
TypeScript
function f1() { function f() { class C<X, Y> { constructor(public x: X, public y: Y) { } } return C; } let C = f(); let v = new C(10, "hello"); let x = v.x; let y = v.y; } function f2() { function f<X>(x: X) { class C<Y> { public x = x; constructor(public y: Y) { } } return C; } let C = f(10); let v = new C("hello"); let x = v.x; let y = v.y; } function f3() { function f<X, Y>(x: X, y: Y) { class C { public x = x; public y = y; } return C; } let C = f(10, "hello"); let v = new C(); let x = v.x; let y = v.y; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/localTypes4.ts
TypeScript
// @allowUnreachableCode: true function f1() { // Type parameters are in scope in parameters and return types function f<T>(x: T): T { return undefined; } } function f2() { // Local types are not in scope in parameters and return types function f(x: T): T { interface T { } return undefined; } } function f3() { // Type parameters and top-level local types are in same declaration space function f<T>() { interface T { } return undefined; } } function f4() { // Local types are block scoped interface T { x: number } let v: T; v.x = 10; if (true) { interface T { x: string } let v: T; v.x = "hello"; } else { v.x = 20; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/localTypes5.ts
TypeScript
function foo<A>() { class X { m<B, C>() { return (function <D>() { class Y<E> { } return new Y<string>(); })<Date>(); } } var x = new X(); return x.m<number, boolean>(); } var x = foo<void>();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/localesObjectArgument.ts
TypeScript
// @target: es2020 const enUS = new Intl.Locale("en-US"); const deDE = new Intl.Locale("de-DE"); const jaJP = new Intl.Locale("ja-JP"); const now = new Date(); const num = 1000; const bigint = 123456789123456789n; const str = ""; const readonlyLocales: Readonly<string[]> = ['de-DE', 'ja-JP']; now.toLocaleString(enUS); now.toLocaleDateString(enUS); now.toLocaleTimeString(enUS); now.toLocaleString([deDE, jaJP]); now.toLocaleDateString([deDE, jaJP]); now.toLocaleTimeString([deDE, jaJP]); num.toLocaleString(enUS); num.toLocaleString([deDE, jaJP]); bigint.toLocaleString(enUS); bigint.toLocaleString([deDE, jaJP]); str.toLocaleLowerCase(enUS); str.toLocaleLowerCase([deDE, jaJP]); str.toLocaleUpperCase(enUS); str.toLocaleUpperCase([deDE, jaJP]); str.localeCompare(str, enUS); str.localeCompare(str, [deDE, jaJP]); new Intl.PluralRules(enUS); new Intl.PluralRules([deDE, jaJP]); new Intl.PluralRules(readonlyLocales); Intl.PluralRules.supportedLocalesOf(enUS); Intl.PluralRules.supportedLocalesOf([deDE, jaJP]); Intl.PluralRules.supportedLocalesOf(readonlyLocales); new Intl.RelativeTimeFormat(enUS); new Intl.RelativeTimeFormat([deDE, jaJP]); new Intl.RelativeTimeFormat(readonlyLocales); Intl.RelativeTimeFormat.supportedLocalesOf(enUS); Intl.RelativeTimeFormat.supportedLocalesOf([deDE, jaJP]); Intl.RelativeTimeFormat.supportedLocalesOf(readonlyLocales); new Intl.Collator(enUS); new Intl.Collator([deDE, jaJP]); new Intl.Collator(readonlyLocales); Intl.Collator.supportedLocalesOf(enUS); Intl.Collator.supportedLocalesOf([deDE, jaJP]); new Intl.DateTimeFormat(enUS); new Intl.DateTimeFormat([deDE, jaJP]); new Intl.DateTimeFormat(readonlyLocales); Intl.DateTimeFormat.supportedLocalesOf(enUS); Intl.DateTimeFormat.supportedLocalesOf([deDE, jaJP]); Intl.DateTimeFormat.supportedLocalesOf(readonlyLocales); new Intl.NumberFormat(enUS); new Intl.NumberFormat([deDE, jaJP]); new Intl.NumberFormat(readonlyLocales); Intl.NumberFormat.supportedLocalesOf(enUS); Intl.NumberFormat.supportedLocalesOf(readonlyLocales);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAndOperatorWithTypeParameters.ts
TypeScript
// The && operator permits the operands to be of any type and produces a result of the same // type as the second operand. function foo<T, U, V/* extends T*/>(t: T, u: U, v: V) { var r1 = t && t; var r2 = u && t; var r3 = v && t; var r4 = t && u; var r5 = u && u; var r6 = v && u; var r7 = t && v; var r8 = u && v; var r9 = v && v; var a: number; var r10 = t && a; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment1.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 declare let a: string | undefined declare let b: string | undefined declare let c: string | undefined declare let d: number | undefined declare let e: number | undefined declare let f: number | undefined declare let g: 0 | 1 | 42 declare let h: 0 | 1 | 42 declare let i: 0 | 1 | 42 a &&= "foo" b ||= "foo" c ??= "foo" d &&= 42 e ||= 42 f ??= 42 g &&= 42 h ||= 42 i ??= 42
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment10.ts
TypeScript
// @target: esnext, es2021, es2020, es2015 var count = 0; var obj = {}; function incr() { return ++count; } const oobj = { obj } obj[incr()] ??= incr(); oobj["obj"][incr()] ??= incr();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment11.ts
TypeScript
// @strict: true // @target: esnext, es2020, es2015 let x: string | undefined; let d: string | undefined; d ?? (d = x ?? "x") d.length; let e: string | undefined; e ??= x ?? "x" e.length
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment2.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 interface A { foo: { bar(): { baz: 0 | 1 | 42 | undefined | '' } baz: 0 | 1 | 42 | undefined | '' } baz: 0 | 1 | 42 | undefined | '' } declare const result: A declare const a: A declare const b: A declare const c: A a.baz &&= result.baz b.baz ||= result.baz c.baz ??= result.baz a.foo["baz"] &&= result.foo.baz b.foo["baz"] ||= result.foo.baz c.foo["baz"] ??= result.foo.baz a.foo.bar().baz &&= result.foo.bar().baz b.foo.bar().baz ||= result.foo.bar().baz c.foo.bar().baz ??= result.foo.bar().baz
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment3.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 interface A { baz: 0 | 1 | 42 | undefined | '' } declare const result: A; declare const a: A; declare const b: A; declare const c: A; (a.baz) &&= result.baz; (b.baz) ||= result.baz; (c.baz) ??= result.baz;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment4.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 // @allowUnreachableCode: false function foo1(results: number[] | undefined) { (results ||= []).push(100); } function foo2(results: number[] | undefined) { (results ??= []).push(100); } function foo3(results: number[] | undefined) { results ||= []; results.push(100); } function foo4(results: number[] | undefined) { results ??= []; results.push(100); } interface ThingWithOriginal { name: string; original?: ThingWithOriginal } declare const v: number function doSomethingWithAlias(thing: ThingWithOriginal | undefined, defaultValue: ThingWithOriginal | undefined) { if (v === 1) { if (thing &&= thing.original) { thing.name; } } else if (v === 2) { if (thing &&= defaultValue) { thing.name; defaultValue.name } } else if (v === 3) { if (thing ||= defaultValue) { thing.name; defaultValue.name; } } else { if (thing ??= defaultValue) { thing.name; defaultValue.name; } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment5.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 function foo1 (f?: (a: number) => void) { f ??= (a => a) f(42) } function foo2 (f?: (a: number) => void) { f ||= (a => a) f(42) } function foo3 (f?: (a: number) => void) { f &&= (a => a) f(42) } function bar1 (f?: (a: number) => void) { f ??= (f.toString(), (a => a)) f(42) } function bar2 (f?: (a: number) => void) { f ||= (f.toString(), (a => a)) f(42) } function bar3 (f?: (a: number) => void) { f &&= (f.toString(), (a => a)) f(42) }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment6.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 function foo1(results: number[] | undefined, results1: number[] | undefined) { (results ||= (results1 ||= [])).push(100); } function foo2(results: number[] | undefined, results1: number[] | undefined) { (results ??= (results1 ??= [])).push(100); } function foo3(results: number[] | undefined, results1: number[] | undefined) { (results &&= (results1 &&= [])).push(100); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment7.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 function foo1(results: number[] | undefined, results1: number[] | undefined) { (results ||= results1 ||= []).push(100); } function foo2(results: number[] | undefined, results1: number[] | undefined) { (results ??= results1 ??= []).push(100); } function foo3(results: number[] | undefined, results1: number[] | undefined) { (results &&= results1 &&= []).push(100); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment8.ts
TypeScript
// @strict: true // @target: esnext, es2021, es2020, es2015 declare const bar: { value?: number[] } | undefined function foo1(results: number[] | undefined) { (results ||= bar?.value ?? []).push(100); } function foo2(results: number[] | undefined) { (results ??= bar?.value ?? []).push(100); } function foo3(results: number[] | undefined) { (results &&= bar?.value ?? []).push(100); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalAssignment9.ts
TypeScript
// @strict: true declare let x: { a?: boolean }; x.a ??= true; x.a &&= false;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalNotOperatorWithAnyOtherType.ts
TypeScript
// ! operator on any type var ANY: any; var ANY1; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; function foo(): any { var a; return a; } class A { public a: any; static foo() { var a; return a; } } module M { export var n: any; } var objA = new A(); // any type var var ResultIsBoolean1 = !ANY1; var ResultIsBoolean2 = !ANY2; var ResultIsBoolean3 = !A; var ResultIsBoolean4 = !M; var ResultIsBoolean5 = !obj; var ResultIsBoolean6 = !obj1; // any type literal var ResultIsBoolean7 = !undefined; var ResultIsBoolean8 = !null; // any type expressions var ResultIsBoolean9 = !ANY2[0]; var ResultIsBoolean10 = !obj1.x; var ResultIsBoolean11 = !obj1.y; var ResultIsBoolean12 = !objA.a; var ResultIsBoolean13 = !M.n; var ResultIsBoolean14 = !foo(); var ResultIsBoolean15 = !A.foo(); var ResultIsBoolean16 = !(ANY + ANY1); var ResultIsBoolean17 = !(null + undefined); var ResultIsBoolean18 = !(null + null); var ResultIsBoolean19 = !(undefined + undefined); // multiple ! operators var ResultIsBoolean20 = !!ANY; var ResultIsBoolean21 = !!!(ANY + ANY1); // miss assignment operators !ANY; !ANY1; !ANY2[0]; !ANY, ANY1; !objA.a; !M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalNotOperatorWithBooleanType.ts
TypeScript
// ! operator on boolean type var BOOLEAN: boolean; function foo(): boolean { return true; } class A { public a: boolean; static foo() { return false; } } module M { export var n: boolean; } var objA = new A(); // boolean type var var ResultIsBoolean1 = !BOOLEAN; // boolean type literal var ResultIsBoolean2 = !true; var ResultIsBoolean3 = !{ x: true, y: false }; // boolean type expressions var ResultIsBoolean4 = !objA.a; var ResultIsBoolean5 = !M.n; var ResultIsBoolean6 = !foo(); var ResultIsBoolean7 = !A.foo(); // multiple ! operators var ResultIsBoolean = !!BOOLEAN; // miss assignment operators !true; !BOOLEAN; !foo(); !true, false; !objA.a; !M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalNotOperatorWithEnumType.ts
TypeScript
// ! operator on enum type enum ENUM { A, B, C }; enum ENUM1 { }; // enum type var var ResultIsBoolean1 = !ENUM; // enum type expressions var ResultIsBoolean2 = !ENUM["B"]; var ResultIsBoolean3 = !(ENUM.B + ENUM["C"]); // multiple ! operators var ResultIsBoolean4 = !!ENUM; var ResultIsBoolean5 = !!!(ENUM["B"] + ENUM.C); // miss assignment operators !ENUM; !ENUM1; !ENUM.B; !ENUM, ENUM1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalNotOperatorWithNumberType.ts
TypeScript
// ! operator on number type var NUMBER: number; var NUMBER1: number[] = [1, 2]; function foo(): number { return 1; } class A { public a: number; static foo() { return 1; } } module M { export var n: number; } var objA = new A(); // number type var var ResultIsBoolean1 = !NUMBER; var ResultIsBoolean2 = !NUMBER1; // number type literal var ResultIsBoolean3 = !1; var ResultIsBoolean4 = !{ x: 1, y: 2}; var ResultIsBoolean5 = !{ x: 1, y: (n: number) => { return n; } }; // number type expressions var ResultIsBoolean6 = !objA.a; var ResultIsBoolean7 = !M.n; var ResultIsBoolean8 = !NUMBER1[0]; var ResultIsBoolean9 = !foo(); var ResultIsBoolean10 = !A.foo(); var ResultIsBoolean11 = !(NUMBER + NUMBER); // multiple ! operator var ResultIsBoolean12 = !!NUMBER; var ResultIsBoolean13 = !!!(NUMBER + NUMBER); // miss assignment operators !1; !NUMBER; !NUMBER1; !foo(); !objA.a; !M.n; !objA.a, M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalNotOperatorWithStringType.ts
TypeScript
// ! operator on string type var STRING: string; var STRING1: string[] = ["", "abc"]; function foo(): string { return "abc"; } class A { public a: string; static foo() { return ""; } } module M { export var n: string; } var objA = new A(); // string type var var ResultIsBoolean1 = !STRING; var ResultIsBoolean2 = !STRING1; // string type literal var ResultIsBoolean3 = !""; var ResultIsBoolean4 = !{ x: "", y: "" }; var ResultIsBoolean5 = !{ x: "", y: (s: string) => { return s; } }; // string type expressions var ResultIsBoolean6 = !objA.a; var ResultIsBoolean7 = !M.n; var ResultIsBoolean8 = !STRING1[0]; var ResultIsBoolean9 = !foo(); var ResultIsBoolean10 = !A.foo(); var ResultIsBoolean11 = !(STRING + STRING); var ResultIsBoolean12 = !STRING.charAt(0); // multiple ! operator var ResultIsBoolean13 = !!STRING; var ResultIsBoolean14 = !!!(STRING + STRING); // miss assignment operators !""; !STRING; !STRING1; !foo(); !objA.a,M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalOrExpressionIsContextuallyTyped.ts
TypeScript
// The || operator permits the operands to be of any type. // If the || expression is contextually typed, the operands are contextually typed by the // same type and the result is of the best common type of the contextual type and the two // operand types. var r: { a: string } = { a: '', b: 123 } || { a: '', b: true };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalOrExpressionIsNotContextuallyTyped.ts
TypeScript
// The || operator permits the operands to be of any type. // If the || expression is not contextually typed, the right operand is contextually typed // by the type of the left operand and the result is of the best common type of the two // operand types. var a: (a: string) => string; // bug 786110 var r = a || ((a) => a.toLowerCase());
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/logicalOrOperatorWithTypeParameters.ts
TypeScript
function fn1<T, U>(t: T, u: U) { var r1 = t || t; var r2: T = t || t; var r3 = t || u; var r4: {} = t || u; } function fn2<T, U/* extends T*/, V/* extends T*/>(t: T, u: U, v: V) { var r1 = t || u; //var r2: T = t || u; var r3 = u || u; var r4: U = u || u; var r5 = u || v; var r6: {} = u || v; //var r7: T = u || v; } function fn3<T extends { a: string; b: string }, U extends { a: string; b: number }>(t: T, u: U) { var r1 = t || u; var r2: {} = t || u; var r3 = t || { a: '' }; var r4: { a: string } = t || u; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/looseThisTypeInFunctions.ts
TypeScript
// @noImplicitAny: true // @noImplicitThis: true interface I { n: number; explicitThis(this: this, m: number): number; } interface Unused { implicitNoThis(m: number): number; } class C implements I { n: number; explicitThis(this: this, m: number): number { return this.n + m; } implicitThis(m: number): number { return this.n + m; } explicitVoid(this: void, m: number): number { return m + 1; } } let c = new C(); c.explicitVoid = c.explicitThis; // error, 'void' is missing everything let o = { n: 101, explicitThis: function (m: number) { return m + this.n.length; // error, 'length' does not exist on 'number' }, implicitThis(m: number): number { return m; } }; let i: I = o; let o2: I = { n: 1001, explicitThis: function (m) { return m + this.n.length; // error, this.n: number, no member 'length' }, } let x = i.explicitThis; let n = x(12); // callee:void doesn't match this:I let u: Unused; let y = u.implicitNoThis; n = y(12); // ok, callee:void matches this:any c.explicitVoid = c.implicitThis // ok, implicitThis(this:any) o.implicitThis = c.implicitThis; // ok, implicitThis(this:any) o.implicitThis = c.explicitThis; // ok, implicitThis(this:any) is assignable to explicitThis(this: this) o.implicitThis = i.explicitThis; i.explicitThis = function(m) { return this.n.length; // error, this.n: number }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/malformedTags.ts
TypeScript
// @allowJS: true // @suppressOutputPathCheck: true // @filename: myFile02.js /** * Checks if `value` is classified as an `Array` object. * * @type Function */ var isArray = Array.isArray;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeAsClauseRelationships.ts
TypeScript
// From original issue #45212: type Methods<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] }; type H<T> = T[keyof Methods<T>]; // Ok // `Filter<T>` only filters out some keys of `T`. type Filter<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] }; // `Modify<T>` might modify some keys of `T`. type Modify<T> = { [P in keyof T as P extends string? `bool${P}`: P]: T[P] }; function fun<T>(val: T) { let x: Filter<T> = val; // Ok let y: Modify<T> = val; // Error } type FilterInclOpt<T> = { [P in keyof T as T[P] extends Function ? P : never]+?: T[P] }; type ModifyInclOpt<T> = { [P in keyof T as P extends string? `bool${P}`: never ]+?: T[P] }; type FilterExclOpt<T> = { [P in keyof T as T[P] extends Function ? P : never]-?: T[P] }; type ModifyExclOpt<T> = { [P in keyof T as P extends string? `bool${P}`: never ]-?: T[P] }; function fun2<T>(val: T) { let x: FilterInclOpt<T> = val; // Ok let y: ModifyInclOpt<T> = val; // Ok let z: FilterExclOpt<T> = val; // Error let w: ModifyExclOpt<T> = val; // Error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeAsClauses.ts
TypeScript
// @strict: true // @declaration: true // Mapped type 'as N' clauses type Getters<T> = { [P in keyof T & string as `get${Capitalize<P>}`]: () => T[P] }; type TG1 = Getters<{ foo: string, bar: number, baz: { z: boolean } }>; // Mapped type with 'as N' clause has no constraint on 'in T' clause type PropDef<K extends keyof any, T> = { name: K, type: T }; type TypeFromDefs<T extends PropDef<keyof any, any>> = { [P in T as P['name']]: P['type'] }; type TP1 = TypeFromDefs<{ name: 'a', type: string } | { name: 'b', type: number } | { name: 'a', type: boolean }>; // No array or tuple type mapping when 'as N' clause present type TA1 = Getters<string[]>; type TA2 = Getters<[number, boolean]>; // Filtering using 'as N' clause type Methods<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] }; type TM1 = Methods<{ foo(): number, bar(x: string): boolean, baz: string | number }>; // Mapping to multiple names using 'as N' clause type DoubleProp<T> = { [P in keyof T & string as `${P}1` | `${P}2`]: T[P] } type TD1 = DoubleProp<{ a: string, b: number }>; // { a1: string, a2: string, b1: number, b2: number } type TD2 = keyof TD1; // 'a1' | 'a2' | 'b1' | 'b2' type TD3<U> = keyof DoubleProp<U>; // keyof DoubleProp<U> type TD4 = TD3<{ a: string, b: number }>; // 'a1' | 'a2' | 'b1' | 'b2' // Repro from #40619 type Lazyify<T> = { [K in keyof T as `get${Capitalize<K & string>}`]: () => T[K] }; interface Person { readonly name: string; age: number; location?: string; } type LazyPerson = Lazyify<Person>; // Repro from #40833 type Example = {foo: string, bar: number}; type PickByValueType<T, U> = { [K in keyof T as T[K] extends U ? K : never]: T[K] }; type T1 = PickByValueType<Example, string>; const e1: T1 = { foo: "hello" }; type T2 = keyof T1; const e2: T2 = "foo"; // Repro from #41133 interface Car { name: string; seats: number; engine: Engine; wheels: Wheel[]; } interface Engine { manufacturer: string; horsepower: number; } interface Wheel { type: "summer" | "winter"; radius: number; } type Primitive = string | number | boolean; type OnlyPrimitives<T> = { [K in keyof T as T[K] extends Primitive ? K : never]: T[K] }; let primitiveCar: OnlyPrimitives<Car>; // { name: string; seats: number; } let keys: keyof OnlyPrimitives<Car>; // "name" | "seats" type KeysOfPrimitives<T> = keyof OnlyPrimitives<T>; let carKeys: KeysOfPrimitives<Car>; // "name" | "seats" // Repro from #41453 type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false; type If<Cond extends boolean, Then, Else> = Cond extends true ? Then : Else; type GetKey<S, V> = keyof { [TP in keyof S as Equal<S[TP], V> extends true ? TP : never]: any }; type GetKeyWithIf<S, V> = keyof { [TP in keyof S as If<Equal<S[TP], V>, TP, never>]: any }; type GetObjWithIf<S, V> = { [TP in keyof S as If<Equal<S[TP], V>, TP, never>]: any }; type Task = { isDone: boolean; }; type Schema = { root: { title: string; task: Task; } Task: Task; }; type Res1 = GetKey<Schema, Schema['root']['task']>; // "Task" type Res2 = GetKeyWithIf<Schema, Schema['root']['task']>; // "Task" type Res3 = keyof GetObjWithIf<Schema, Schema['root']['task']>; // "Task" // Repro from #44019 type KeysExtendedBy<T, U> = keyof { [K in keyof T as U extends T[K] ? K : never] : T[K] }; interface M { a: boolean; b: number; } function f(x: KeysExtendedBy<M, number>) { return x; } f("a"); // Error, should allow only "b" type NameMap = { 'a': 'x', 'b': 'y', 'c': 'z' }; // Distributive, will be simplified type TS0<T> = keyof { [P in keyof T as keyof Record<P, number>]: string }; type TS1<T> = keyof { [P in keyof T as Extract<P, 'a' | 'b' | 'c'>]: string }; type TS2<T> = keyof { [P in keyof T as P & ('a' | 'b' | 'c')]: string }; type TS3<T> = keyof { [P in keyof T as Exclude<P, 'a' | 'b' | 'c'>]: string }; type TS4<T> = keyof { [P in keyof T as NameMap[P & keyof NameMap]]: string }; type TS5<T> = keyof { [P in keyof T & keyof NameMap as NameMap[P]]: string }; type TS6<T, U, V> = keyof { [ K in keyof T as V & (K extends U ? K : never)]: string }; // Non-distributive, won't be simplified type TN0<T> = keyof { [P in keyof T as T[P] extends number ? P : never]: string }; type TN1<T> = keyof { [P in keyof T as number extends T[P] ? P : never]: string }; type TN2<T> = keyof { [P in keyof T as 'a' extends P ? 'x' : 'y']: string }; type TN3<T> = keyof { [P in keyof T as Exclude<Exclude<Exclude<P, 'c'>, 'b'>, 'a'>]: string }; type TN4<T, U> = keyof { [K in keyof T as (K extends U ? T[K] : never) extends T[K] ? K : never]: string }; type TN5<T, U> = keyof { [K in keyof T as keyof { [P in K as T[P] extends U ? K : never]: true }]: string }; // repro from https://github.com/microsoft/TypeScript/issues/55129 type Fruit = | { name: "apple"; color: "red"; } | { name: "banana"; color: "yellow"; } | { name: "orange"; color: "orange"; }; type Result1<T extends {name: string | number; color: string | number }> = { [Key in T as `${Key['name']}:${Key['color']}`]: unknown }; type Result2<T extends {name: string | number; color: string | number }> = keyof { [Key in T as `${Key['name']}:${Key['color']}`]: unknown } type Test1 = keyof Result1<Fruit> // "apple:red" | "banana:yellow" | "orange:orange" type Test2 = Result2<Fruit> // "apple:red" | "banana:yellow" | "orange:orange"
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeConstraints.ts
TypeScript
// @strict: true function f0<T extends { a: string, b: string }>(obj: Pick<T, Extract<keyof T, 'b'>>) { obj.b; } function f1<T extends { a: string, b: string }>(obj: Pick<T, Exclude<keyof T, 'a'>>) { obj.b; } function f2<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T | U, keyof (T | U)>) { obj.b; } function f3<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T & U, keyof (T & U)>) { obj.a; obj.b; obj.c; } function f4<T extends { a: string, b: string }>(obj: Record<Exclude<keyof T, 'b'> | 'c', string>) { obj.a; obj.c; } // Repro from #28821 type TargetProps = { foo: string, bar: string }; const modifier = <T extends TargetProps>(targetProps: T) => { let {bar, ...rest} = targetProps; rest.foo; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeConstraints2.ts
TypeScript
// @strict: true // @declaration: true // @target: es2017 type Mapped1<K extends string> = { [P in K]: { a: P } }; function f1<K extends string>(obj: Mapped1<K>, key: K) { const x: { a: K } = obj[key]; } type Mapped2<K extends string> = { [P in K as `get${P}`]: { a: P } }; function f2<K extends string>(obj: Mapped2<K>, key: `get${K}`) { const x: { a: K } = obj[key]; // Error } type Mapped3<K extends string> = { [P in K as Uppercase<P>]: { a: P } }; function f3<K extends string>(obj: Mapped3<K>, key: Uppercase<K>) { const x: { a: K } = obj[key]; // Error } type Mapped4<K extends `_${string}`> = { [P in K]: P; }; function f4<K extends `_${string}`>(obj: Mapped4<K>, key: keyof Mapped4<K>) { let s: `_${string}` = obj[key]; } type Mapped5<K extends string> = { [P in K as P extends `_${string}` ? P : never]: P; }; function f5<K extends string>(obj: Mapped5<K>, key: keyof Mapped5<K>) { let s: `_${string}` = obj[key]; } // repro from #53066#issuecomment-1913384757 type Mapped6<K extends string> = { [P in K as `_${P}`]: P; }; function f6<K extends string>(obj: Mapped6<K>, key: keyof Mapped6<K>) { let s: `_${string}` = obj[key]; // Error } // Repro from #47794 type Foo<T extends string> = { [RemappedT in T as `get${RemappedT}`]: RemappedT; }; const get = <T extends string>(t: T, foo: Foo<T>): T => foo[`get${t}`]; // Type 'Foo<T>[`get${T}`]' is not assignable to type 'T' // Repro from #48626 interface Bounds { min: number; max: number; } type NumericBoundsOf<T> = { [K in keyof T as T[K] extends number | undefined ? K : never]: Bounds; } function validate<T extends object>(obj: T, bounds: NumericBoundsOf<T>) { for (const [key, val] of Object.entries(obj)) { const boundsForKey = bounds[key as keyof NumericBoundsOf<T>]; if (boundsForKey) { const { min, max } = boundsForKey; if (min > val || max < val) return false; } } return true; } // repro from #50030 type ObjectWithUnderscoredKeys<K extends string> = { [k in K as `_${k}`]: true; }; function genericTest<K extends string>(objectWithUnderscoredKeys: ObjectWithUnderscoredKeys<K>, key: K) { const shouldBeTrue: true = objectWithUnderscoredKeys[`_${key}`]; // assignability fails here, but ideally should not }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeErrors.ts
TypeScript
// @strictNullChecks: true // @declaration: true interface Shape { name: string; width: number; height: number; visible: boolean; } interface Named { name: string; } interface Point { x: number; y: number; } // Constraint checking type T00 = { [P in P]: string }; // Error type T01 = { [P in number]: string }; // Error type T02 = { [P in Date]: number }; // Error type T03 = Record<Date, number>; // Error type T10 = Pick<Shape, "name">; type T11 = Pick<Shape, "foo">; // Error type T12 = Pick<Shape, "name" | "foo">; // Error type T13 = Pick<Shape, keyof Named>; type T14 = Pick<Shape, keyof Point>; // Error type T15 = Pick<Shape, never>; type T16 = Pick<Shape, undefined>; // Error function f1<T>(x: T) { let y: Pick<Shape, T>; // Error } function f2<T extends string | number>(x: T) { let y: Pick<Shape, T>; // Error } function f3<T extends keyof Shape>(x: T) { let y: Pick<Shape, T>; } function f4<T extends keyof Named>(x: T) { let y: Pick<Shape, T>; } // Type identity checking function f10<T>() { type K = keyof T; var x: { [P in keyof T]: T[P] }; var x: { [Q in keyof T]: T[Q] }; var x: { [R in K]: T[R] }; } function f11<T>() { var x: { [P in keyof T]: T[P] }; var x: { [P in keyof T]?: T[P] }; // Error var x: { readonly [P in keyof T]: T[P] }; // Error var x: { readonly [P in keyof T]?: T[P] }; // Error } function f12<T>() { var x: { [P in keyof T]: T[P] }; var x: { [P in keyof T]: T[P][] }; // Error } // Check that inferences to mapped types are secondary declare function objAndReadonly<T>(primary: T, secondary: Readonly<T>): T; declare function objAndPartial<T>(primary: T, secondary: Partial<T>): T; function f20() { let x1 = objAndReadonly({ x: 0, y: 0 }, { x: 1 }); // Error let x2 = objAndReadonly({ x: 0, y: 0 }, { x: 1, y: 1 }); let x3 = objAndReadonly({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error } function f21() { let x1 = objAndPartial({ x: 0, y: 0 }, { x: 1 }); let x2 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1 }); let x3 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error } // Verify use of Pick<T, K> for setState functions (#12793) interface Foo { a: string; b?: number; } function setState<T, K extends keyof T>(obj: T, props: Pick<T, K>) { for (let k in props) { obj[k] = props[k]; } } let foo: Foo = { a: "hello", b: 42 }; setState(foo, { a: "test", b: 43 }) setState(foo, { a: "hi" }); setState(foo, { b: undefined }); setState(foo, { }); setState(foo, foo); setState(foo, { a: undefined }); // Error setState(foo, { c: true }); // Error class C<T> { state: T; setState<K extends keyof T>(props: Pick<T, K>) { for (let k in props) { this.state[k] = props[k]; } } } let c = new C<Foo>(); c.setState({ a: "test", b: 43 }); c.setState({ a: "hi" }); c.setState({ b: undefined }); c.setState({ }); c.setState(foo); c.setState({ a: undefined }); // Error c.setState({ c: true }); // Error type T2 = { a?: number, [key: string]: any }; let x1: T2 = { a: 'no' }; // Error let x2: Partial<T2> = { a: 'no' }; // Error let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error // Repro from #13044 type Foo2<T, F extends keyof T> = { pf: {[P in F]?: T[P]}, pt: {[P in T]?: T[P]}, // note: should be in keyof T }; type O = {x: number, y: boolean}; let o: O = {x: 5, y: false}; let f: Foo2<O, 'x'> = { pf: {x: 7}, pt: {x: 7, y: false}, }; // Repro from #28170 function test1<T, K extends keyof T>(obj: Pick<T, K>) { let x = obj.foo; // Error } function test2<T, K extends keyof T>(obj: Record<K, number>) { let x = obj.foo; // Error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeErrors2.ts
TypeScript
// @strictNullChecks: true // @declaration: true // Repros from #17238 type AB = { a: 'a' b: 'a' }; type T1<K extends keyof AB> = { [key in AB[K]]: true }; type T2<K extends 'a'|'b'> = T1<K>[K]; // Error type R = AB[keyof AB]; // "a" type T3 = { [key in R]: true }; type T4<K extends 'a'|'b'> = T3[K] // Error type T5<S extends 'a'|'b'|'extra'> = {[key in AB[S]]: true}[S]; // Error type T6<S extends 'a'|'b', L extends 'a'|'b'> = {[key in AB[S]]: true}[L]; // Error type T7<S extends 'a'|'b', L extends 'a'> = {[key in AB[S]]: true}[L];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeIndexSignatureModifiers.ts
TypeScript
// @strict: true // @noEmit: true // https://github.com/microsoft/TypeScript/issues/14295 interface Obj1 { readonly [key: string]: string; } type Res1 = Pick<Obj1, keyof Obj1> interface Obj2 { concreteProp: 'hello'; readonly [key: string]: string; } type Res2 = Pick<Obj2, keyof Obj2> interface Obj3 { readonly [key: string]: string; readonly [key: number]: 'foo'; } type Res3 = Pick<Obj3, keyof Obj3> interface Obj4 { [key: string]: string; readonly [key: number]: 'foo'; } type Res4 = Pick<Obj4, keyof Obj4> interface Obj5 { readonly [key: string]: string; [key: number]: 'foo'; } type Res5 = Pick<Obj5, keyof Obj5> type Identity<T> = { [P in keyof T]: T[P]; } interface Obj6 { readonly [key: `wow${string}`]: 'foo'; } type Res6 = Identity<Obj6> interface Obj7 { [key: string]: string; readonly [key: `wow${string}`]: 'foo'; } type Res7 = Identity<Obj7> interface Obj8 { readonly [key: string]: string; [key: `wow${string}`]: 'foo'; } type Res8 = Identity<Obj8> type StrippingPick<T, K extends keyof T> = { -readonly [P in K]: T[P]; } interface Obj9 { readonly [key: string]: string; } type Res9 = StrippingPick<Obj9, keyof Obj9> interface Obj10 { readonly [key: string]: string; readonly [key: number]: 'foo'; } type Res10 = StrippingPick<Obj10, keyof Obj10> interface Obj11 { [key: string]: string; readonly [key: number]: 'foo'; } type Res11 = StrippingPick<Obj11, keyof Obj11> interface Obj12 { readonly [key: string]: string; [key: number]: 'foo'; } type Res12 = StrippingPick<Obj12, keyof Obj12> type StrippingIdentity<T> = { -readonly [P in keyof T]: T[P]; } interface Obj13 { readonly [key: `wow${string}`]: 'foo'; } type Res13 = StrippingIdentity<Obj13>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeInferenceErrors.ts
TypeScript
// @strict: true // Repro from #19316 type ComputedOf<T> = { [K in keyof T]: () => T[K]; } declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void; foo({ props: { x: 10, y: 20 }, computed: { bar(): number { let z = this.bar; return 42; }, baz: 42 } });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeModifiers.ts
TypeScript
// @strictNullChecks: true // @noimplicitany: true type T = { a: number, b: string }; type TP = { a?: number, b?: string }; type TR = { readonly a: number, readonly b: string }; type TPR = { readonly a?: number, readonly b?: string }; var v00: "a" | "b"; var v00: keyof T; var v00: keyof TP; var v00: keyof TR; var v00: keyof TPR; var v01: T; var v01: { [P in keyof T]: T[P] }; var v01: Pick<T, keyof T>; var v01: Pick<Pick<T, keyof T>, keyof T>; var v02: TP; var v02: { [P in keyof T]?: T[P] }; var v02: Partial<T>; var v02: { [P in keyof TP]: TP[P] } var v02: Pick<TP, keyof TP>; var v03: TR; var v03: { readonly [P in keyof T]: T[P] }; var v03: Readonly<T>; var v03: { [P in keyof TR]: TR[P] } var v03: Pick<TR, keyof TR>; var v04: TPR; var v04: { readonly [P in keyof T]?: T[P] }; var v04: Partial<TR>; var v04: Readonly<TP>; var v04: Partial<Readonly<T>>; var v04: Readonly<Partial<T>>; var v04: { [P in keyof TPR]: TPR[P] } var v04: Pick<TPR, keyof T>; type Boxified<T> = { [P in keyof T]: { x: T[P] } }; type B = { a: { x: number }, b: { x: string } }; type BP = { a?: { x: number }, b?: { x: string } }; type BR = { readonly a: { x: number }, readonly b: { x: string } }; type BPR = { readonly a?: { x: number }, readonly b?: { x: string } }; var b00: "a" | "b"; var b00: keyof B; var b00: keyof BP; var b00: keyof BR; var b00: keyof BPR; var b01: B; var b01: { [P in keyof B]: B[P] }; var b01: Pick<B, keyof B>; var b01: Pick<Pick<B, keyof B>, keyof B>; var b02: BP; var b02: { [P in keyof B]?: B[P] }; var b02: Partial<B>; var b02: { [P in keyof BP]: BP[P] } var b02: Pick<BP, keyof BP>; var b03: BR; var b03: { readonly [P in keyof B]: B[P] }; var b03: Readonly<B>; var b03: { [P in keyof BR]: BR[P] } var b03: Pick<BR, keyof BR>; var b04: BPR; var b04: { readonly [P in keyof B]?: B[P] }; var b04: Partial<BR>; var b04: Readonly<BP>; var b04: Partial<Readonly<B>>; var b04: Readonly<Partial<B>>; var b04: { [P in keyof BPR]: BPR[P] } var b04: Pick<BPR, keyof BPR>; type Foo = { prop: number, [x: string]: number }; function f1(x: Partial<Foo>) { x.prop; // ok (x["other"] || 0).toFixed(); } function f2(x: Readonly<Foo>) { x.prop; // ok x["other"].toFixed(); } function f3(x: Boxified<Foo>) { x.prop; // ok x["other"].x.toFixed(); } function f4(x: { [P in keyof Foo]: Foo[P] }) { x.prop; // ok x["other"].toFixed(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeOverlappingStringEnumKeys.ts
TypeScript
// #37859 enum TerrestrialAnimalTypes { CAT = "cat", DOG = "dog" }; enum AlienAnimalTypes { CAT = "cat", }; type AnimalTypes = TerrestrialAnimalTypes | AlienAnimalTypes; interface TerrestrialCat { type: TerrestrialAnimalTypes.CAT; address: string; } interface AlienCat { type: AlienAnimalTypes.CAT planet: string; } type Cats = TerrestrialCat | AlienCat; type CatMap = { [V in AnimalTypes]: Extract<Cats, { type: V }>[] }; const catMap: CatMap = { cat: [ { type: TerrestrialAnimalTypes.CAT, address: "" }, { type: AlienAnimalTypes.CAT, planet: "" } ], dog: [] as never[] };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeRelationships.ts
TypeScript
// @strictNullChecks: true // @declaration: true function f1<T>(x: T, k: keyof T) { return x[k]; } function f2<T, K extends keyof T>(x: T, k: K) { return x[k]; } function f3<T, U extends T>(x: T, y: U, k: keyof T) { x[k] = y[k]; y[k] = x[k]; // Error } function f4<T, U extends T, K extends keyof T>(x: T, y: U, k: K) { x[k] = y[k]; y[k] = x[k]; // Error } function f5<T, U extends T>(x: T, y: U, k: keyof U) { x[k] = y[k]; // Error y[k] = x[k]; // Error } function f6<T, U extends T, K extends keyof U>(x: T, y: U, k: K) { x[k] = y[k]; // Error y[k] = x[k]; // Error } function f10<T>(x: T, y: Partial<T>, k: keyof T) { x[k] = y[k]; // Error y[k] = x[k]; } function f11<T, K extends keyof T>(x: T, y: Partial<T>, k: K) { x[k] = y[k]; // Error y[k] = x[k]; } function f12<T, U extends T>(x: T, y: Partial<U>, k: keyof T) { x[k] = y[k]; // Error y[k] = x[k]; // Error } function f13<T, U extends T, K extends keyof T>(x: T, y: Partial<U>, k: K) { x[k] = y[k]; // Error y[k] = x[k]; // Error } function f20<T>(x: T, y: Readonly<T>, k: keyof T) { x[k] = y[k]; y[k] = x[k]; // Error } function f21<T, K extends keyof T>(x: T, y: Readonly<T>, k: K) { x[k] = y[k]; y[k] = x[k]; // Error } function f22<T, U extends T>(x: T, y: Readonly<U>, k: keyof T) { x[k] = y[k]; y[k] = x[k]; // Error } function f23<T, U extends T, K extends keyof T>(x: T, y: Readonly<U>, k: K) { x[k] = y[k]; y[k] = x[k]; // Error } type Thing = { a: string, b: string }; function f30<T>(x: T, y: Partial<T>) { x = y; // Error y = x; } function f31<T extends Thing>(x: Partial<Thing>, y: Partial<T>) { x = y; y = x; // Error } function f40<T>(x: T, y: Readonly<T>) { x = y; y = x; } function f41<T extends Thing>(x: Readonly<Thing>, y: Readonly<T>) { x = y; y = x; // Error } type Item = { name: string; } type ItemMap = { [x: string]: Item; } function f50<T extends ItemMap>(obj: T, key: keyof T) { let item: Item = obj[key]; return obj[key].name; } function f51<T extends ItemMap, K extends keyof T>(obj: T, key: K) { let item: Item = obj[key]; return obj[key].name; } type T1<T> = { [P in keyof T]: T[P]; } type T2<T> = { [P in keyof T]: T[P]; } function f60<U>(x: T1<U>, y: T2<U>) { x = y; y = x; } type Identity<T> = { [P in keyof T]: T[P]; } function f61<U>(x: Identity<U>, y: Partial<U>) { x = y; // Error y = x; } function f62<U>(x: Identity<U>, y: Readonly<U>) { x = y; y = x; } function f70<T>(x: { [P in keyof T]: T[P] }, y: { [P in keyof T]: T[P] }) { x = y; y = x; } function f71<T, U extends T>(x: { [P in keyof T]: T[P] }, y: { [P in keyof T]: U[P] }) { x = y; y = x; // Error } function f72<T, U extends T>(x: { [P in keyof T]: T[P] }, y: { [P in keyof U]: U[P] }) { x = y; y = x; // Error } function f73<T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in keyof T]: T[P] }) { x = y; y = x; // Error } function f74<T, U extends T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in keyof U]: U[P] }) { x = y; y = x; // Error } function f75<T, U extends T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in keyof T]: U[P] }) { x = y; y = x; // Error } function f76<T, U extends T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in K]: U[P] }) { x = y; y = x; // Error } function f80<T>(t: T): Partial<T> { return t; } function f81<T, K extends keyof T>(t: T, k: K): Partial<T[K]> { return t[k]; } function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2): Partial<T[K1][K2]> { return t[k1][k2]; } // #31070 type Numeric<T> = { [K in keyof T]?: number }; function f90<T extends { x: number }>() { const n: Numeric<T> = { x: 1 }; } function f<T extends { x: {} }>(): Partial<T> { return undefined! as T; } // #32365 interface SettingsTypes { audio: { volume: string; }; video: { resolution: string; }; } interface Settings<Params extends { [K in keyof Params]?: string }> { config: Params; } type ConcreteSettingsResult1 = Settings<SettingsTypes["audio"]>; type ConcreteSettingsResult2 = Settings<SettingsTypes["audio" | "video"]>; type GenericSettingsAccess<T extends keyof SettingsTypes> = Settings<SettingsTypes[T]>; type GenericSettingsResult1 = GenericSettingsAccess<"audio">; type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypeWithAny.ts
TypeScript
// @strict: true // @declaration: true type Item = { value: string }; type ItemMap<T> = { [P in keyof T]: Item }; declare let x0: keyof any; declare let x1: { [P in any]: Item }; declare let x2: { [P in string]: Item }; declare let x3: { [P in keyof any]: Item }; declare let x4: ItemMap<any>; // Repro from #19152 type Data = { value: string; } type StrictDataMap<T> = { [P in keyof T]: Data } declare let z: StrictDataMap<any>; for (let id in z) { let data = z[id]; let x = data.notAValue; // Error } // Issue #46169. // We want mapped types whose constraint is `keyof T` to // map over `any` differently, depending on whether `T` // is constrained to array and tuple types. type Arrayish<T extends unknown[]> = { [K in keyof T]: T[K] }; type Objectish<T extends unknown> = { [K in keyof T]: T[K] }; // When a mapped type whose constraint is `keyof T` is instantiated, // `T` may be instantiated with a `U` which is constrained to // array and tuple types. *Ideally*, when `U` is later instantiated with `any`, // the result should also be some sort of array; however, at the moment we don't seem // to have an easy way to preserve that information. More than just that, it would be // inconsistent for two instantiations of `Objectish<any>` to produce different outputs // depending on the usage-site. As a result, `IndirectArrayish` does not act like `Arrayish`. type IndirectArrayish<U extends unknown[]> = Objectish<U>; function bar(arrayish: Arrayish<any>, objectish: Objectish<any>, indirectArrayish: IndirectArrayish<any>) { let arr: any[]; arr = arrayish; arr = objectish; arr = indirectArrayish; } declare function stringifyArray<T extends readonly any[]>(arr: T): { -readonly [K in keyof T]: string }; let abc: any[] = stringifyArray(void 0 as any); declare function stringifyPair<T extends readonly [any, any]>(arr: T): { -readonly [K in keyof T]: string }; let def: [any, any] = stringifyPair(void 0 as any); // Repro from #46582 type Evolvable<E extends Evolver> = { [P in keyof E]: never; }; type Evolver<T extends Evolvable<any> = any> = { [key in keyof Partial<T>]: never; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypes1.ts
TypeScript
// @strictNullChecks: true // @declaration: true type Item = { a: string, b: number, c: boolean }; type T00 = { [P in "x" | "y"]: number }; type T01 = { [P in "x" | "y"]: P }; type T02 = { [P in "a" | "b"]: Item[P]; } type T03 = { [P in keyof Item]: Date }; type T10 = { [P in keyof Item]: Item[P] }; type T11 = { [P in keyof Item]?: Item[P] }; type T12 = { readonly [P in keyof Item]: Item[P] }; type T13 = { readonly [P in keyof Item]?: Item[P] }; type T20 = { [P in keyof Item]: Item[P] | null }; type T21 = { [P in keyof Item]: Array<Item[P]> }; type T30 = { [P in keyof any]: void }; type T31 = { [P in keyof string]: void }; type T32 = { [P in keyof number]: void }; type T33 = { [P in keyof boolean]: void }; type T34 = { [P in keyof undefined]: void }; type T35 = { [P in keyof null]: void }; type T36 = { [P in keyof void]: void }; type T37 = { [P in keyof symbol]: void }; type T38 = { [P in keyof never]: void }; type T40 = { [P in string]: void }; type T43 = { [P in "a" | "b"]: void }; type T44 = { [P in "a" | "b" | "0" | "1"]: void }; type T47 = { [P in string | "a" | "b" | "0" | "1"]: void }; declare function f1<T1>(): { [P in keyof T1]: void }; declare function f2<T1 extends string>(): { [P in keyof T1]: void }; declare function f3<T1 extends number>(): { [P in keyof T1]: void }; declare function f4<T1 extends Number>(): { [P in keyof T1]: void }; let x1 = f1(); let x2 = f2(); let x3 = f3(); let x4 = f4();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypes2.ts
TypeScript
// @strictNullChecks: true // @declaration: true function verifyLibTypes<T, K extends keyof T, U>() { var x1: Partial<T>; var x1: { [P in keyof T]?: T[P] }; var x2: Readonly<T>; var x2: { readonly [P in keyof T]: T[P] }; var x3: Pick<T, K>; var x3: { [P in K]: T[P] }; var x4: Record<K, U>; var x4: { [P in K]: U }; } type Proxy<T> = { get(): T; set(value: T): void; } type Proxify<T> = { [P in keyof T]: Proxy<T[P]>; } type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]>; }; declare function assign<T>(obj: T, props: Partial<T>): void; declare function freeze<T>(obj: T): Readonly<T>; declare function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>; declare function mapObject<K extends string, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>; declare function proxify<T>(obj: T): Proxify<T>; interface Point { x: number; y: number; } interface Shape { name: string; width: number; height: number; location: Point; } interface PartialShape { name?: string; width?: number; height?: number; location?: Point; } interface ReadonlyShape { readonly name: string; readonly width: number; readonly height: number; readonly location: Point; } function f0(s1: Shape, s2: Shape) { assign(s1, { name: "circle" }); assign(s2, { width: 10, height: 20 }); } function f1(shape: Shape) { var frozen: ReadonlyShape; var frozen: Readonly<Shape>; var frozen = freeze(shape); } function f2(shape: Shape) { var partial: PartialShape; var partial: Partial<Shape>; var partial: Partial<Shape> = {}; } function f3(shape: Shape) { const x = pick(shape, "name", "location"); // { name: string, location: Point } } function f4() { const rec = { foo: "hello", bar: "world", baz: "bye" }; const lengths = mapObject(rec, s => s.length); // { foo: number, bar: number, baz: number } } function f5(shape: Shape) { const p = proxify(shape); let name = p.name.get(); p.width.set(42); } function f6(shape: DeepReadonly<Shape>) { let name = shape.name; // string let location = shape.location; // DeepReadonly<Point> let x = location.x; // number }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypes3.ts
TypeScript
// @declaration: true class Box<P> { value: P; } type Boxified<T> = { [K in keyof T]: Box<T[K]>; } declare function boxify<T>(obj: T): Boxified<T>; declare function unboxify<T>(obj: Boxified<T>): T; interface Bacon { isPerfect: boolean; weight: number; } interface BoxifiedBacon { isPerfect: Box<boolean>; weight: Box<number>; } function f1(b: Bacon) { let bb = boxify(b); let isPerfect = bb.isPerfect.value; let weight = bb.weight.value; } function f2(bb: Boxified<Bacon>) { let b = unboxify(bb); // Infer Bacon for T let bool = b.isPerfect; let weight = b.weight; } function f3(bb: BoxifiedBacon) { let b = unboxify<Bacon>(bb); // Explicit type parameter required let bool = b.isPerfect; let weight = bb.weight; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypes4.ts
TypeScript
// @strictNullChecks: true // @declaration: true type Box<T> = { }; type Boxified<T> = { [P in keyof T]: Box<T[P]>; }; function boxify<T>(obj: T): Boxified<T> { if (typeof obj === "object") { let result = {} as Boxified<T>; for (let k in obj) { result[k] = { value: obj[k] }; } return result; } return <any>obj; } type A = { a: string }; type B = { b: string }; type C = { c: string }; function f1(x: A | B | C | undefined) { return boxify(x); } type T00 = Partial<A | B | C>; type T01 = Readonly<A | B | C | null | undefined>; type T02 = Boxified<A | B[] | C | string> type T03 = Readonly<string | number | boolean | null | undefined | void>; type T04 = Boxified<string | number | boolean | null | undefined | void>; type T05 = Partial<"hello" | "world" | 42>; type BoxifiedWithSentinel<T, U> = { [P in keyof T]: Box<T[P]> | U; } type T10 = BoxifiedWithSentinel<A | B | C, null>; type T11 = BoxifiedWithSentinel<A | B | C, undefined>; type T12 = BoxifiedWithSentinel<string, undefined>; type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]>; }; type Foo = { x: number; y: { a: string, b: number }; z: boolean; }; type DeepReadonlyFoo = { readonly x: number; readonly y: { readonly a: string, readonly b: number }; readonly z: boolean; }; var x1: DeepReadonly<Foo>; var x1: DeepReadonlyFoo; // Repro from #13232 type Z = { a: number }; type Clone<T> = { [P in keyof (T & {})]: (T & {})[P]; }; type M = Clone<Z>; // M should be { a: number } var z1: Z; var z1: Clone<Z>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypes5.ts
TypeScript
// @strict: true function f<T>(p: Partial<T>, r: Readonly<T>, pr: Partial<Readonly<T>>, rp: Readonly<Partial<T>>) { let a1: Partial<T> = p; let a2: Partial<T> = r; let a3: Partial<T> = pr; let a4: Partial<T> = rp; let b1: Readonly<T> = p; // Error let b2: Readonly<T> = r; let b3: Readonly<T> = pr; // Error let b4: Readonly<T> = rp; // Error let c1: Partial<Readonly<T>> = p; let c2: Partial<Readonly<T>> = r; let c3: Partial<Readonly<T>> = pr; let c4: Partial<Readonly<T>> = rp; let d1: Readonly<Partial<T>> = p; let d2: Readonly<Partial<T>> = r; let d3: Readonly<Partial<T>> = pr; let d4: Readonly<Partial<T>> = rp; } // Repro from #17682 type State = { [key: string]: string | boolean | number | null; }; type Args1<T extends State> = { readonly previous: Readonly<Partial<T>>; readonly current: Readonly<Partial<T>>; }; type Args2<T extends State> = { readonly previous: Partial<Readonly<T>>; readonly current: Partial<Readonly<T>>; }; function doit<T extends State>() { let previous: Partial<T> = Object.create(null); let current: Partial<T> = Object.create(null); let args1: Args1<T> = { previous, current }; let args2: Args2<T> = { previous, current }; } type State2 = { foo: number, bar: string }; type Args3 = { readonly previous: Readonly<Partial<State2>>; readonly current: Readonly<Partial<State2>>; }; type Args4 = { readonly previous: Partial<Readonly<State2>>; readonly current: Partial<Readonly<State2>>; }; function doit2() { let previous: Partial<State2> = Object.create(null); let current: Partial<State2> = Object.create(null); let args1: Args3 = { previous, current }; let args2: Args4 = { previous, current }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypes6.ts
TypeScript
// @strict: true // @declaration: true type T00<T> = { [P in keyof T]: T[P] }; type T01<T> = { [P in keyof T]?: T[P] }; type T02<T> = { [P in keyof T]+?: T[P] }; type T03<T> = { [P in keyof T]-?: T[P] }; type T04<T> = { readonly [P in keyof T]: T[P] }; type T05<T> = { readonly [P in keyof T]?: T[P] }; type T06<T> = { readonly [P in keyof T]+?: T[P] }; type T07<T> = { readonly [P in keyof T]-?: T[P] }; type T08<T> = { +readonly [P in keyof T]: T[P] }; type T09<T> = { +readonly [P in keyof T]?: T[P] }; type T10<T> = { +readonly [P in keyof T]+?: T[P] }; type T11<T> = { +readonly [P in keyof T]-?: T[P] }; type T12<T> = { -readonly [P in keyof T]: T[P] }; type T13<T> = { -readonly [P in keyof T]?: T[P] }; type T14<T> = { -readonly [P in keyof T]+?: T[P] }; type T15<T> = { -readonly [P in keyof T]-?: T[P] }; function f1<T>(x: Required<T>, y: T, z: Partial<T>) { x = x; x = y; // Error x = z; // Error y = x; y = y; y = z; // Error z = x; z = y; z = z; } type Denullified<T> = { [P in keyof T]-?: NonNullable<T[P]> }; function f2<T>(w: Denullified<T>, x: Required<T>, y: T, z: Partial<T>) { w = w; w = x; // Error w = y; // Error w = z; // Error x = w; x = x; x = y; // Error x = z; // Error y = w; y = x; y = y; y = z; // Error z = w; z = x; z = y; z = z; } function f3<T>(w: Denullified<T>, x: Required<T>, y: T, z: Partial<T>) { w = {}; // Error x = {}; // Error y = {}; // Error z = {}; } type Readwrite<T> = { -readonly [P in keyof T]: T[P]; } function f10<T>(x: Readonly<T>, y: T, z: Readwrite<T>) { x = x; x = y; x = z; y = x; y = y; y = z; z = x; z = y; z = z; } type Foo = { a: number; b: number | undefined; c?: number; d?: number | undefined; } declare let x1: Foo; x1.a; // number x1.b; // number | undefined x1.c; // number | undefined x1.d; // number | undefined x1 = { a: 1 }; // Error x1 = { a: 1, b: 1 }; x1 = { a: 1, b: 1, c: 1 }; x1 = { a: 1, b: 1, c: 1, d: 1 }; declare let x2: Required<Foo>; x1.a; // number x1.b; // number | undefined x1.c; // number x1.d; // number x2 = { a: 1 }; // Error x2 = { a: 1, b: 1 }; // Error x2 = { a: 1, b: 1, c: 1 }; // Error x2 = { a: 1, b: 1, c: 1, d: 1 }; type Bar = { a: number; readonly b: number; } declare let x3: Bar; x3.a = 1; x3.b = 1; // Error declare let x4: Readonly<Bar>; x4.a = 1; // Error x4.b = 1; // Error declare let x5: Readwrite<Bar>; x5.a = 1; x5.b = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypesAndObjects.ts
TypeScript
// @strictNullChecks: true // @declaration: true function f1<T>(x: Partial<T>, y: Readonly<T>) { let obj: {}; obj = x; obj = y; } function f2<T>(x: Partial<T>, y: Readonly<T>) { let obj: { [x: string]: any }; obj = x; obj = y; } function f3<T>(x: Partial<T>) { x = {}; } // Repro from #12900 interface Base { foo: { [key: string]: any }; bar: any; baz: any; } interface E1<T> extends Base { foo: T; } interface Something { name: string, value: string }; interface E2 extends Base { foo: Partial<Something>; // or other mapped type } interface E3<T> extends Base { foo: Partial<T>; // or other mapped type } // Repro from #13747 class Form<T> { private values: {[P in keyof T]?: T[P]} = {} }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypesArraysTuples.ts
TypeScript
// @strict: true // @declaration: true type Box<T> = { value: T }; type Boxified<T> = { [P in keyof T]: Box<T[P]> }; type T00 = Boxified<[number, string?, ...boolean[]]>; type T01 = Partial<[number, string?, ...boolean[]]>; type T02 = Required<[number, string?, ...boolean[]]>; type T10 = Boxified<string[]>; type T11 = Partial<string[]>; type T12 = Required<string[]>; type T13 = Boxified<ReadonlyArray<string>>; type T14 = Partial<ReadonlyArray<string>>; type T15 = Required<ReadonlyArray<string>>; type T20 = Boxified<(string | undefined)[]>; type T21 = Partial<(string | undefined)[]>; type T22 = Required<(string | undefined)[]>; type T23 = Boxified<ReadonlyArray<string | undefined>>; type T24 = Partial<ReadonlyArray<string | undefined>>; type T25 = Required<ReadonlyArray<string | undefined>>; type T30 = Boxified<Partial<string[]>>; type T31 = Partial<Boxified<string[]>>; type A = { a: string }; type B = { b: string }; type T40 = Boxified<A | A[] | ReadonlyArray<A> | [A, B] | string | string[]>; type ReadWrite<T> = { -readonly [P in keyof T] : T[P] }; type T50 = Readonly<string[]>; type T51 = Readonly<[number, number]>; type T52 = Partial<Readonly<string[]>>; type T53 = Readonly<Partial<string[]>>; type T54 = ReadWrite<Required<T53>>; declare function unboxify<T>(x: Boxified<T>): T; declare let x10: [Box<number>, Box<string>, ...Box<boolean>[]]; let y10 = unboxify(x10); declare let x11: Box<number>[]; let y11 = unboxify(x11); declare let x12: { a: Box<number>, b: Box<string[]> }; let y12 = unboxify(x12); declare function nonpartial<T>(x: Partial<T>): T; declare let x20: [number | undefined, string?, ...boolean[]]; let y20 = nonpartial(x20); declare let x21: (number | undefined)[]; let y21 = nonpartial(x21); declare let x22: { a: number | undefined, b?: string[] }; let y22 = nonpartial(x22); type __Awaited<T> = T extends PromiseLike<infer U> ? U : T; type Awaitified<T> = { [P in keyof T]: __Awaited<T[P]> }; declare function all<T extends any[]>(...values: T): Promise<Awaitified<T>>; function f1(a: number, b: Promise<number>, c: string[], d: Promise<string[]>) { let x1 = all(a); let x2 = all(a, b); let x3 = all(a, b, c); let x4 = all(a, b, c, d); } function f2<T extends any[]>(a: Boxified<T>) { let x: Box<any> | undefined = a.pop(); let y: Box<any>[] = a.concat(a); } // Repro from #26163 type ElementType<T> = T extends Array<infer U> ? U : never; type Mapped<T> = { [K in keyof T]: T[K] }; type F<T> = ElementType<Mapped<T>>; type R1 = F<[string, number, boolean]>; // string | number | boolean type R2 = ElementType<Mapped<[string, number, boolean]>>; // string | number | boolean // Repro from #26163 declare function acceptArray(arr: any[]): void; declare function mapArray<T extends any[]>(arr: T): Mapped<T>; function acceptMappedArray<T extends any[]>(arr: T) { acceptArray(mapArray(arr)); } // Repro from #26163 type Unconstrained<T> = ElementType<Mapped<T>>; type T1 = Unconstrained<[string, number, boolean]>; // string | number | boolean type Constrained<T extends any[]> = ElementType<Mapped<T>>; type T2 = Constrained<[string, number, boolean]>; // string | number | boolean
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypesGenericTuples.ts
TypeScript
// @strict: true // @noEmit: true // Property keys are `number` following the fixed part of a tuple type K<T> = { [P in keyof T]: P }; type M<T> = { [P in keyof T]: T[P] }; type KA = K<[string, string, boolean]>; // ["0", "1", "2"] type KB = K<[string, string, ...string[], string]>; // ["0", "1", ...number[], number] type KC = K<[...string[]]>; // number[] type KD = K<string[]>; // number[] type A = { a: string }; type B = { b: string }; type C = { c: string }; type D = { d: string }; type V0<T extends unknown[]> = [A, B?, ...T, ...C[]] type V1<T extends unknown[]> = [A, ...T, B, ...C[], D] type K0<T extends unknown[]> = K<V0<T>>; // ["0", "1"?, ...K<T>, ...number[]] type K1<T extends unknown[]> = K<V1<T>>; // ["0", ...K<T>, number, ...number[], number] type M0<T extends unknown[]> = M<V0<T>>; // [A, B?, ...M<T>, ...C[]] type M1<T extends unknown[]> = M<V1<T>>; // [A, ...M<T>, B, ...C[], D] // Repro from #48856 type Keys<O extends unknown[]> = { [K in keyof O]: K }; type Keys1 = Keys<[string, ...string[]]>; type Keys2 = Keys<[string, ...string[], number]>; // Repro from #56888 type T1 = ['a', 'b', 'c'] extends readonly [infer H, ...unknown[]] ? H : never; // "a" type T2 = ['a', 'b', 'c'] extends Readonly<[infer H, ...unknown[]]> ? H : never; // "a" type T3 = ['a', 'b', 'c'] extends readonly [...unknown[], infer L] ? L : never; // "c" type T4 = ['a', 'b', 'c'] extends Readonly<[...unknown[], infer L]> ? L : never; // "c" // Repro from #56888 type R1<T> = readonly [...unknown[], T]; // readonly [...unknown[], T] type R2<T> = Readonly<[...unknown[], T]>; // readonly [...unknown[], T]
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mappedTypesGenericTuples2.ts
TypeScript
// @strict: true // @lib: esnext // @noEmit: true // https://github.com/microsoft/TypeScript/issues/57389 declare function getT<T>(): T; Promise.all([getT<string>(), ...getT<any>()]).then((result) => { const head = result[0]; // string const tail = result.slice(1); // any[] tail satisfies string[]; // ok });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/memberFunctionOverloadMixingStaticAndInstance.ts
TypeScript
class C { foo(); static foo(); // error } class D { static foo(); foo(); // error } class E<T> { foo(x: T); static foo(x: number); // error } class F<T> { static foo(x: number); foo(x: T); // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/memberFunctionsWithPrivateOverloads.ts
TypeScript
class C { private foo(x: number); private foo(x: number, y: string); private foo(x: any, y?: any) { } private bar(x: 'hi'); private bar(x: string); private bar(x: number, y: string); private bar(x: any, y?: any) { } private static foo(x: number); private static foo(x: number, y: string); private static foo(x: any, y?: any) { } private static bar(x: 'hi'); private static bar(x: string); private static bar(x: number, y: string); private static bar(x: any, y?: any) { } } class D<T> { private foo(x: number); private foo(x: T, y: T); private foo(x: any, y?: any) { } private bar(x: 'hi'); private bar(x: string); private bar(x: T, y: T); private bar(x: any, y?: any) { } private static foo(x: number); private static foo(x: number, y: number); private static foo(x: any, y?: any) { } private static bar(x: 'hi'); private static bar(x: string); private static bar(x: number, y: number); private static bar(x: any, y?: any) { } } var c: C; var r = c.foo(1); // error var d: D<number>; var r2 = d.foo(2); // error var r3 = C.foo(1); // error var r4 = D.bar(''); // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/memberFunctionsWithPublicOverloads.ts
TypeScript
class C { public foo(x: number); public foo(x: number, y: string); public foo(x: any, y?: any) { } public bar(x: 'hi'); public bar(x: string); public bar(x: number, y: string); public bar(x: any, y?: any) { } public static foo(x: number); public static foo(x: number, y: string); public static foo(x: any, y?: any) { } public static bar(x: 'hi'); public static bar(x: string); public static bar(x: number, y: string); public static bar(x: any, y?: any) { } } class D<T> { public foo(x: number); public foo(x: T, y: T); public foo(x: any, y?: any) { } public bar(x: 'hi'); public bar(x: string); public bar(x: T, y: T); public bar(x: any, y?: any) { } public static foo(x: number); public static foo(x: number, y: string); public static foo(x: any, y?: any) { } public static bar(x: 'hi'); public static bar(x: string); public static bar(x: number, y: string); public static bar(x: any, y?: any) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/memberFunctionsWithPublicPrivateOverloads.ts
TypeScript
class C { private foo(x: number); public foo(x: number, y: string); // error private foo(x: any, y?: any) { } private bar(x: 'hi'); public bar(x: string); // error private bar(x: number, y: string); private bar(x: any, y?: any) { } private static foo(x: number); public static foo(x: number, y: string); // error private static foo(x: any, y?: any) { } protected baz(x: string); // error protected baz(x: number, y: string); // error private baz(x: any, y?: any) { } private static bar(x: 'hi'); public static bar(x: string); // error private static bar(x: number, y: string); private static bar(x: any, y?: any) { } protected static baz(x: 'hi'); public static baz(x: string); // error protected static baz(x: number, y: string); protected static baz(x: any, y?: any) { } } class D<T> { private foo(x: number); public foo(x: T, y: T); // error private foo(x: any, y?: any) { } private bar(x: 'hi'); public bar(x: string); // error private bar(x: T, y: T); private bar(x: any, y?: any) { } private baz(x: string); protected baz(x: number, y: string); // error private baz(x: any, y?: any) { } private static foo(x: number); public static foo(x: number, y: string); // error private static foo(x: any, y?: any) { } private static bar(x: 'hi'); public static bar(x: string); // error private static bar(x: number, y: string); private static bar(x: any, y?: any) { } public static baz(x: string); // error protected static baz(x: number, y: string); protected static baz(x: any, y?: any) { } } var c: C; var r = c.foo(1); // error var d: D<number>; var r2 = d.foo(2); // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergeClassInterfaceAndModule.ts
TypeScript
interface C1 {} declare class C1 {} module C1 {} declare class C2 {} interface C2 {} module C2 {} declare class C3 {} module C3 {} interface C3 {} module C4 {} declare class C4 {} // error -- class declaration must precede module declaration interface C4 {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergeThreeInterfaces.ts
TypeScript
// interfaces with the same root module should merge // basic case interface A { foo: string; } interface A { bar: number; } interface A { baz: boolean; } var a: A; var r1 = a.foo var r2 = a.bar; var r3 = a.baz; // basic generic case interface B<T> { foo: T; } interface B<T> { bar: T; } interface B<T> { baz: T; } var b: B<string>; var r4 = b.foo var r5 = b.bar; var r6 = b.baz; // basic non-generic and generic case inside a module module M { interface A { foo: string; } interface A { bar: number; } interface A { baz: boolean; } var a: A; var r1 = a.foo; // BUG 856491 var r2 = a.bar; // any, should be number // BUG 856491 var r3 = a.baz; // any, should be boolean interface B<T> { foo: T; } interface B<T> { bar: T; } interface B<T> { baz: T; } var b: B<string>; var r4 = b.foo // BUG 856491 var r5 = b.bar; // any, should be number // BUG 856491 var r6 = b.baz; // any, should be boolean }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergeThreeInterfaces2.ts
TypeScript
// two interfaces with the same root module should merge // root module now multiple module declarations module M2 { export interface A { foo: string; } var a: A; var r1 = a.foo; var r2 = a.bar; } module M2 { export interface A { bar: number; } export interface A { baz: boolean; } var a: A; var r1 = a.foo; var r2 = a.bar; var r3 = a.baz; } // same as above but with an additional level of nesting and third module declaration module M2 { export module M3 { export interface A { foo: string; } var a: A; var r1 = a.foo; var r2 = a.bar; } } module M2 { export module M3 { export interface A { bar: number; } var a: A; var r1 = a.foo var r2 = a.bar; var r3 = a.baz; } } module M2 { export module M3 { export interface A { baz: boolean; } var a: A; var r1 = a.foo var r2 = a.bar; var r3 = a.baz; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergeTwoInterfaces.ts
TypeScript
// two interfaces with the same root module should merge // basic case interface A { foo: string; } interface A { bar: number; } var a: A; var r1 = a.foo var r2 = a.bar; // basic generic case interface B<T> { baz: string; foo: T; } interface B<T> { bar: T; } var b: B<string>; var r3 = b.foo var r4 = b.bar; // basic non-generic and generic case inside a module module M { interface A { foo: string; } interface A { bar: number; } var a: A; var r1 = a.foo; // BUG 856491 var r2 = a.bar; // any, should be number interface B<T> { foo: T; } interface B<T> { bar: T; } var b: B<string>; var r3 = b.foo // BUG 856491 var r4 = b.bar; // any, should be string }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergeTwoInterfaces2.ts
TypeScript
// two interfaces with the same root module should merge // root module now multiple module declarations module M2 { export interface A { foo: string; } var a: A; var r1 = a.foo var r2 = a.bar; } module M2 { export interface A { bar: number; } var a: A; var r1 = a.foo var r2 = a.bar; } // same as above but with an additional level of nesting module M2 { export module M3 { export interface A { foo: string; } var a: A; var r1 = a.foo var r2 = a.bar; } } module M2 { export module M3 { export interface A { bar: number; } var a: A; var r1 = a.foo var r2 = a.bar; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedClassInterface.ts
TypeScript
// @declaration: true // @Filename: file1.ts declare class C1 { } interface C1 { } interface C2 { } declare class C2 { } class C3 { } interface C3 { } interface C4 { } class C4 { } interface C5 { x1: number; } declare class C5 { x2: number; } interface C5 { x3: number; } interface C5 { x4: number; } // checks if properties actually were merged var c5 : C5; c5.x1; c5.x2; c5.x3; c5.x4; // @Filename: file2.ts declare class C6 { } interface C7 { } // @Filename: file3.ts interface C6 { } declare class C7 { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInheritedClassInterface.ts
TypeScript
interface BaseInterface { required: number; optional?: number; } class BaseClass { baseMethod() { } baseNumber: number; } interface Child extends BaseInterface { additional: number; } class Child extends BaseClass { classNumber: number; method() { } } interface ChildNoBaseClass extends BaseInterface { additional2: string; } class ChildNoBaseClass { classString: string; method2() { } } class Grandchild extends ChildNoBaseClass { } // checks if properties actually were merged var child : Child; child.required; child.optional; child.additional; child.baseNumber; child.classNumber; child.baseMethod(); child.method(); var grandchild: Grandchild; grandchild.required; grandchild.optional; grandchild.additional2; grandchild.classString; grandchild.method2();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInheritedMembersSatisfyAbstractBase.ts
TypeScript
abstract class BaseClass { abstract bar: number; } class Broken extends BaseClass {} // declaration merging should satisfy abstract bar interface IGetters { bar: number; } interface Broken extends IGetters {} new Broken().bar class IncorrectlyExtends extends BaseClass {} interface IncorrectGetters { bar: string; } interface IncorrectlyExtends extends IncorrectGetters {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithConflictingPropertyNames.ts
TypeScript
interface A { x: string; // error } interface A { x: number; } module M { interface A<T> { x: T; } interface A<T> { x: number; // error } } module M2 { interface A<T> { x: T; } } module M2 { interface A<T> { x: number; // ok, different declaration space than other M2 } } module M3 { export interface A<T> { x: T; } } module M3 { export interface A<T> { x: number; // error } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithConflictingPropertyNames2.ts
TypeScript
interface A { x: string; // error } interface A { x: string; // error } module M { interface A<T> { x: T; } interface A<T> { x: T; // error } } module M2 { interface A<T> { x: T; } } module M2 { interface A<T> { x: T; // ok, different declaration space than other M2 } } module M3 { export interface A<T> { x: T; } } module M3 { export interface A<T> { x: T; // error } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithIndexers.ts
TypeScript
// indexers should behave like other members when merging interface declarations interface A { [x: number]: string; } interface A { [x: string]: { length: number }; } var a: A; var r = a[1]; var r2 = a['1']; var r3 = a['hi'];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithIndexers2.ts
TypeScript
// indexers should behave like other members when merging interface declarations interface A { [x: number]: string; // error } interface A { [x: string]: { length: string }; // error } interface A2 { [x: number]: string; 'a': number; //error } interface A2 { [x: string]: { length: number }; 1: { length: number }; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithInheritedPrivates.ts
TypeScript
class C { private x: number; } interface A extends C { y: string; } interface A { z: string; } class D implements A { // error private x: number; y: string; z: string; } class E implements A { // error x: number; y: string; z: string; } var a: A; var r = a.x; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithInheritedPrivates2.ts
TypeScript
class C { private x: number; } class C2 { private w: number; } interface A extends C { y: string; } interface A extends C2 { z: string; } class D extends C implements A { // error private w: number; y: string; z: string; } class E extends C2 implements A { // error w: number; y: string; z: string; } var a: A; var r = a.x; // error var r2 = a.w; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithInheritedPrivates3.ts
TypeScript
class C { private x: number; } class C2 { private x: number; } interface A extends C { // error y: string; } interface A extends C2 { z: string; } class D extends C implements A { // error y: string; z: string; } module M { class C { private x: string; } class C2 { private x: number; } interface A extends C { // error, privates conflict y: string; } interface A extends C2 { z: string; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithMultipleBases.ts
TypeScript
// merged interfaces behave as if all extends clauses from each declaration are merged together // no errors expected class C { a: number; } class C2 { b: number; } interface A extends C { y: string; } interface A extends C2 { z: string; } class D implements A { a: number; b: number; y: string; z: string; } var a: A; var r = a.a; // generic interfaces in a module module M { class C<T> { a: T; } class C2<T> { b: T; } interface A<T> extends C<T> { y: T; } interface A<T> extends C2<string> { z: T; } class D implements A<boolean> { a: boolean; b: string; y: boolean; z: boolean; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithMultipleBases2.ts
TypeScript
// merged interfaces behave as if all extends clauses from each declaration are merged together // no errors expected class C { a: number; } class C2 { b: number; } class C3 { c: string; } class C4 { d: string; } interface A extends C, C3 { y: string; } interface A extends C2, C4 { z: string; } class D implements A { a: number; b: number; c: string; d: string; y: string; z: string; } var a: A; var r = a.a; // generic interfaces in a module module M { class C<T> { a: T; } class C2<T> { b: T; } class C3<T> { c: T; } class C4<T> { d: T; } interface A<T> extends C<T>, C3<T> { y: T; } interface A<T> extends C2<string>, C4<string> { z: T; } class D implements A<boolean> { a: boolean; b: string; c: boolean; d: string; y: boolean; z: boolean; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithMultipleBases3.ts
TypeScript
// merged interfaces behave as if all extends clauses from each declaration are merged together // no errors expected class C<T> { a: T; } class C2<T> { b: T; } class C3<T> { c: T; } class C4<T> { d: T; } interface A<T> extends C<string>, C3<string> { y: T; } interface A<T> extends C<string>, C4<string> { z: T; } class D implements A<boolean> { a: string; b: Date; c: string; d: string; y: boolean; z: boolean; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedInterfacesWithMultipleBases4.ts
TypeScript
// merged interfaces behave as if all extends clauses from each declaration are merged together class C<T> { a: T; } class C2<T> { b: T; } class C3<T> { c: T; } class C4<T> { d: T; } interface A<T> extends C<string>, C3<string> { // error y: T; } interface A<T> extends C<number>, C4<string> { z: T; } class D implements A<boolean> { a: string; b: string; c: string; d: string; y: boolean; z: boolean; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mergedWithLocalValue.ts
TypeScript
// @Filename: a.ts export type A = "a"; // @Filename: b.ts import type { A } from "./a"; const A: A = "a"; A.toUpperCase();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/methodSignaturesWithOverloads.ts
TypeScript
// Object type literals permit overloads with optionality but they must match var c: { func4?(x: number): number; func4(s: string): string; // error, mismatched optionality func5?: { (x: number): number; (s: string): string; }; }; var c2: { func4<T>(x: T): number; func4? <T>(s: T): string; // error, mismatched optionality func5?: { <T>(x: T): number; <T>(s: T): string; }; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/methodSignaturesWithOverloads2.ts
TypeScript
// Object type literals permit overloads with optionality but they must match var c: { func4?(x: number): number; func4?(s: string): string; func5?: { (x: number): number; (s: string): string; }; }; // no errors c.func4 = c.func5; c.func5 = c.func4; var c2: { func4?<T>(x: T): number; func4? <T>(s: T): string; func5?: { <T>(x: T): number; <T>(s: T): string; }; }; // no errors c2.func4 = c2.func5; c2.func5 = c2.func4;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/methodsReturningThis.ts
TypeScript
// @filename: input.js // @outFile: output.js // @allowJs: true function Class() { } // error: 'Class' doesn't have property 'notPresent' Class.prototype.containsError = function () { return this.notPresent; }; // lots of methods that return this, which caused out-of-memory in #9527 Class.prototype.m1 = function (a, b, c, d, tx, ty) { return this; }; Class.prototype.m2 = function (x, y) { return this; }; Class.prototype.m3 = function (x, y) { return this; }; Class.prototype.m4 = function (angle) { return this; }; Class.prototype.m5 = function (matrix) { return this; }; Class.prototype.m6 = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) { return this; }; Class.prototype.m7 = function(matrix) { return this; }; Class.prototype.m8 = function() { return this; }; Class.prototype.m9 = function () { return this; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/missingAndExcessProperties.ts
TypeScript
// Missing properties function f1() { var { x, y } = {}; var { x = 1, y } = {}; var { x, y = 1 } = {}; var { x = 1, y = 1 } = {}; } // Missing properties function f2() { var x: number, y: number; ({ x, y } = {}); ({ x: x = 1, y } = {}); ({ x, y: y = 1 } = {}); ({ x: x = 1, y: y = 1 } = {}); } // Excess properties function f3() { var { } = { x: 0, y: 0 }; var { x } = { x: 0, y: 0 }; var { y } = { x: 0, y: 0 }; var { x, y } = { x: 0, y: 0 }; } // Excess properties function f4() { var x: number, y: number; ({ } = { x: 0, y: 0 }); ({ x } = { x: 0, y: 0 }); ({ y } = { x: 0, y: 0 }); ({ x, y } = { x: 0, y: 0 }); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mixedPropertyElementAccessAssignmentDeclaration.ts
TypeScript
// Should not crash: #34642 var arr = []; arr[0].prop[2] = {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University