_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
TypeScript/tests/cases/compiler/functionWithDefaultParameterWithNoStatements10.ts_0_52
function foo(a = [0]) { } function bar(a = [0]) { }
{ "end_byte": 52, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionWithDefaultParameterWithNoStatements10.ts" }
TypeScript/tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts_0_145
namespace A { function foo() { if (true) { B. namespace B { export function baz() { } }
{ "end_byte": 145, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/errorRecoveryWithDotFollowedByNamespaceKeyword.ts" }
TypeScript/tests/cases/compiler/mappedTypeInferenceCircularity.ts_0_135
// Repro from #12511 type HTML = { [K in 'div']: Block<HTML> }; type Block<P> = <T>(func: HTML) => {}; declare var h: HTML; h.div(h);
{ "end_byte": 135, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/mappedTypeInferenceCircularity.ts" }
TypeScript/tests/cases/compiler/tslibReExportHelpers2.ts_0_969
// @module: nodenext // @importHelpers: true // @target: es2021 // @Filename: /node_modules/tslib/index.d.ts export declare function __classPrivateFieldGet<T extends object, V>( receiver: T, state: { has(o: T): boolean, get(o: T): V | undefined }, kind?: "f" ): V; export declare function __classPrivateFieldGet<T extends new (...args: any[]) => unknown, V>( receiver: T, state: T, kind: "f", f: { value: V } ): V; // @Filename: /node_modules/tslib/index.d.mts export { __classPrivateFieldGet } from "./index.js"; // @Filename: /node_modules/tslib/package.json { "name": "tslib", "version": "1.0.0", "types": "index.d.ts", "exports": { ".": { "types": { "import": "./index.d.mts", "default": "./index.d.ts" } } } } // @Filename: /index.mts export class Foo { constructor() { console.log(Foo.#test()); } static #test() { return 'success'; } }
{ "end_byte": 969, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/tslibReExportHelpers2.ts" }
TypeScript/tests/cases/compiler/reverseMappedContravariantInference.ts_0_204
// @strict: true // Repro from #21273 declare function conforms<T>(source: { [K in keyof T]: (val: T[K]) => boolean }): (value: T) => boolean; conforms({ foo: (v: string) => false })({ foo: "hello" });
{ "end_byte": 204, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reverseMappedContravariantInference.ts" }
TypeScript/tests/cases/compiler/outModuleConcatAmd.ts_0_212
// @target: ES5 // @sourcemap: true // @declaration: true // @module: amd // @outFile: all.js // @Filename: ref/a.ts export class A { } // @Filename: b.ts import {A} from "./ref/a"; export class B extends A { }
{ "end_byte": 212, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/outModuleConcatAmd.ts" }
TypeScript/tests/cases/compiler/indexedAccessAndNullableNarrowing.ts_0_1263
// @strict: true // @noEmit: true function f1<T extends Record<string, any>, K extends keyof T>(x: T[K] | undefined) { if (x === undefined) return; x; // T[K] & ({} | null) if (x === undefined) return; x; // T[K] & ({} | null) } function f2<T extends Record<string, any>, K extends keyof T>(x: T[K] | null) { if (x === null) return; x; // T[K] & ({} | undefined) if (x === null) return; x; // T[K] & ({} | undefined) } function f3<T, K extends keyof T>(t: T[K], p1: Partial<T>[K] & {}, p2: Partial<T>[K] & ({} | null)) { t = p1; t = p2; } // https://github.com/microsoft/TypeScript/issues/57693 type AnyObject = Record<string, any>; type State = AnyObject; declare function hasOwnProperty<T extends AnyObject>( object: T, prop: PropertyKey, ): prop is keyof T; interface Store<S = State> { setState<K extends keyof S>(key: K, value: S[K]): void; } export function syncStoreProp< S extends State, P extends Partial<S>, K extends keyof S, >(store: Store<S>, props: P, key: K) { const value = hasOwnProperty(props, key) ? props[key] : undefined; if (value === undefined) return; store.setState(key, value); if (value === undefined) return; store.setState(key, value); }
{ "end_byte": 1263, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/indexedAccessAndNullableNarrowing.ts" }
TypeScript/tests/cases/compiler/genericObjectLitReturnType.ts_0_176
class X<T> { f(t: T) { return { a: t }; } } var x: X<number>; var t1 = x.f(5); t1.a = 5; // Should not error: t1 should have type {a: number}, instead has type {a: T}
{ "end_byte": 176, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericObjectLitReturnType.ts" }
TypeScript/tests/cases/compiler/jsDeclarationEmitExportAssignedArray.ts_0_191
// @allowJs: true // @checkJs: true // @emitDeclarationOnly: true // @declaration: true // @filename: file.js module.exports = [{ name: 'other', displayName: 'Other', defaultEnabled: true }];
{ "end_byte": 191, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsDeclarationEmitExportAssignedArray.ts" }
TypeScript/tests/cases/compiler/arrayAssignmentTest3.ts_0_229
// The following gives no error // Michal saw no error if he used number instead of B, // but I do... class B {} class a { constructor(public x: string, public y: number, z: B[]) { } } var xx = new a(null, 7, new B());
{ "end_byte": 229, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrayAssignmentTest3.ts" }
TypeScript/tests/cases/compiler/typeParameterWithInvalidConstraintType.ts_0_156
class A<T extends T> { foo() { var x: T; var a = x.foo(); var b = new x(123); var c = x[1]; var d = x(); } }
{ "end_byte": 156, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeParameterWithInvalidConstraintType.ts" }
TypeScript/tests/cases/compiler/typePredicateTopLevelTypeParameter.ts_0_348
// @strict: true // Repro from #51980 function getPermissions(user: string) { if (user === 'Jack') return 'admin'; return undefined; } const admins = ['Mike', 'Joe'].map(e => getPermissions(e)); function isDefined<T>(a: T | undefined): a is T { return a !== undefined; } const foundAdmins = admins.filter(isDefined); // "admin"[]
{ "end_byte": 348, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typePredicateTopLevelTypeParameter.ts" }
TypeScript/tests/cases/compiler/unusedVariablesinForLoop2.ts_0_118
//@noUnusedLocals:true //@noUnusedParameters:true function f1 () { for (const elem in ["a", "b", "c"]) { } }
{ "end_byte": 118, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedVariablesinForLoop2.ts" }
TypeScript/tests/cases/compiler/strictFunctionTypes1.ts_0_1537
// @strict: true // @declaration: true declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void; declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T; declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T; interface Func<T> { (x: T): void } declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>; declare function fo(x: Object): void; declare function fs(x: string): void; declare function fx(f: (x: "def") => void): void; const x1 = f1(fo, fs); // (x: string) => void const x2 = f2("abc", fo, fs); // "abc" const x3 = f3("abc", fo, fx); // "abc" | "def" const x4 = f4(fo, fs); // Func<string> declare const never: never; const x10 = f2(never, fo, fs); // string const x11 = f3(never, fo, fx); // "def" // Repro from #21112 declare function foo<T>(a: ReadonlyArray<T>): T; let x = foo([]); // never // Modified repros from #26127 interface A { a: string } interface B extends A { b: string } declare function acceptUnion(x: A | number): void; declare function acceptA(x: A): void; declare let a: A; declare let b: B; declare function coAndContra<T>(value: T, func: (t: T) => void): T; const t1: A = coAndContra(a, acceptUnion); const t2: B = coAndContra(b, acceptA); const t3: A = coAndContra(never, acceptA); declare function coAndContraArray<T>(value: T[], func: (t: T) => void): T[]; const t4: A[] = coAndContraArray([a], acceptUnion); const t5: B[] = coAndContraArray([b], acceptA); const t6: A[] = coAndContraArray([], acceptA);
{ "end_byte": 1537, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/strictFunctionTypes1.ts" }
TypeScript/tests/cases/compiler/promisesWithConstraints.ts_0_393
interface Promise<T> { then<U>(cb: (x: T) => Promise<U>): Promise<U>; } interface CPromise<T extends { x: any; }> { then<U extends { x: any; }>(cb: (x: T) => Promise<U>): Promise<U>; } interface Foo { x; } interface Bar { x; y; } var a: Promise<Foo>; var b: Promise<Bar>; a = b; // ok b = a; // ok var a2: CPromise<Foo>; var b2: CPromise<Bar>; a2 = b2; // ok b2 = a2; // was error
{ "end_byte": 393, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/promisesWithConstraints.ts" }
TypeScript/tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts_0_2042
// @strict: true type Either<L, A> = Left<L, A> | Right<L, A>; class Left<L, A> { readonly _tag: 'Left' = 'Left' readonly _A!: A readonly _L!: L constructor(readonly value: L) {} /** The given function is applied if this is a `Right` */ map<B>(f: (a: A) => B): Either<L, B> { return this as any } ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> { return null as any } } class Right<L, A> { readonly _tag: 'Right' = 'Right' readonly _A!: A readonly _L!: L constructor(readonly value: A) {} map<B>(f: (a: A) => B): Either<L, B> { return new Right(f(this.value)) } ap<B>(fab: Either<L, (a: A) => B>): Either<L, B> { return null as any; } } class Type<A, O = A, I = unknown> { readonly _A!: A; readonly _O!: O; readonly _I!: I; constructor( /** a unique name for this codec */ readonly name: string, /** a custom type guard */ readonly is: (u: unknown) => u is A, /** succeeds if a value of type I can be decoded to a value of type A */ readonly validate: (input: I, context: {}[]) => Either<{}[], A>, /** converts a value of type A to a value of type O */ readonly encode: (a: A) => O ) {} /** a version of `validate` with a default context */ decode(i: I): Either<{}[], A> { return null as any; } } interface Any extends Type<any, any, any> {} type TypeOf<C extends Any> = C["_A"]; type ToB<S extends {[_ in string | number | symbol]: Any}> = { [k in keyof S]: TypeOf<S[k]> }; type ToA<S> = { [k in keyof S]: Type<S[k]> }; type NeededInfo<MyNamespaceSchema = {}> = { ASchema: ToA<MyNamespaceSchema>; }; export type MyInfo = NeededInfo<ToB<{ initialize: any }>>; const tmp1: MyInfo = null!; function tmp2<N extends NeededInfo>(n: N) {} // tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same) class Server<X extends NeededInfo> {} export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`
{ "end_byte": 2042, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts" }
TypeScript/tests/cases/compiler/inferFromGenericFunctionReturnTypes3.ts_0_3957
// @strict: true // @target: es6 // @declaration: true // Repros from #5487 function truePromise(): Promise<true> { return Promise.resolve(true); } interface Wrap<T> { value: T; } function wrap<T>(value: T): Wrap<T> { return { value }; } function wrappedFoo(): Wrap<'foo'> { return wrap('foo'); } function wrapBar(value: 'bar'): Wrap<'bar'> { return { value }; } function wrappedBar(): Wrap<'bar'> { const value = 'bar'; const inferred = wrapBar(value); const literal = wrapBar('bar'); const value2: string = 'bar'; const literal2 = wrapBar(value2); // Error return wrap(value); } function wrappedBaz(): Wrap<'baz'> { const value: 'baz' = 'baz'; return wrap(value); } // Repro from #11152 interface FolderContentItem { type: 'folder' | 'file'; } let a: FolderContentItem[] = []; a = [1, 2, 3, 4, 5].map(v => ({ type: 'folder' })); // Repro from #11312 let arr: Array<[number, number]> = [[1, 2]] let mappedArr: Array<[number, number]> = arr.map(([x, y]) => { return [x, y]; }) // Repro from #13594 export namespace DiagnosticSeverity { export const Error = 1; export const Warning = 2; export const Information = 3; export const Hint = 4; } export type DiagnosticSeverity = 1 | 2 | 3 | 4; export interface Diagnostic { severity?: DiagnosticSeverity; code?: number | string; source?: string; message: string; } function bug(): Diagnostic[] { let values: any[] = []; return values.map((value) => { return { severity: DiagnosticSeverity.Error, message: 'message' } }); } // Repro from #22870 function objectToMap(obj: any) { return new Map(Object.keys(obj).map(key => [key, obj[key]])); }; // Repro from #24352 interface Person { phoneNumbers: { __typename: 'PhoneNumber'; }[]; } function createPerson(): Person { return { phoneNumbers: [1].map(() => ({ __typename: 'PhoneNumber' })) }; } // Repro from #26621 type Box<T> = { value: T }; declare function box<T>(value: T): Box<T>; type WinCondition = | { type: 'win', player: string } | { type: 'draw' }; let zz: Box<WinCondition> = box({ type: 'draw' }); type WinType = 'win' | 'draw'; let yy: Box<WinType> = box('draw'); // Repro from #27074 interface OK<T> { kind: "OK"; value: T; } export function ok<T>(value: T): OK<T> { return { kind: "OK", value: value }; } let result: OK<[string, number]> = ok(["hello", 12]); // Repro from #25889 interface I { code: 'mapped', name: string, } const a3: I[] = ['a', 'b'].map(name => { return { code: 'mapped', name, } }); // Repro from https://www.memsql.com/blog/porting-30k-lines-of-code-from-flow-to-typescript/ type Player = { name: string; age: number; position: "STRIKER" | "GOALKEEPER", }; type F = () => Promise<Array<Player>>; const f1: F = () => { return Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]); }; // Breaking change repros from #29478 declare function foldLeft<U>(z: U, f: (acc: U, t: boolean) => U): U; let res: boolean = foldLeft(true, (acc, t) => acc && t); // Error enum State { A, B } type Foo = { state: State } declare function bar<T>(f: () => T[]): T[]; let x: Foo[] = bar(() => !!true ? [{ state: State.A }] : [{ state: State.B }]); // Error // Repros from #31443 enum Enum { A, B } class ClassWithConvert<T> { constructor(val: T) { } convert(converter: { to: (v: T) => T; }) { } } function fn<T>(arg: ClassWithConvert<T>, f: () => ClassWithConvert<T>) { } fn(new ClassWithConvert(Enum.A), () => new ClassWithConvert(Enum.A)); type Func<T> = (x: T) => T; declare function makeFoo<T>(x: T): Func<T>; declare function baz<U>(x: Func<U>, y: Func<U>): void; baz(makeFoo(Enum.A), makeFoo(Enum.A));
{ "end_byte": 3957, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/inferFromGenericFunctionReturnTypes3.ts" }
TypeScript/tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts_3_121
clare class C { baz(): any; foo(n: number): any; } interface C { foo(n: number): any; bar(): any; }
{ "end_byte": 121, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts" }
TypeScript/tests/cases/compiler/cloduleWithRecursiveReference.ts_0_81
module M { export class C { } export module C { export var C = M.C } }
{ "end_byte": 81, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/cloduleWithRecursiveReference.ts" }
TypeScript/tests/cases/compiler/namedFunctionExpressionInModule.ts_0_78
module Variables{ var x = function bar(a, b, c) { } x(1, 2, 3); }
{ "end_byte": 78, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/namedFunctionExpressionInModule.ts" }
TypeScript/tests/cases/compiler/overloadResolutionTest1.ts_1_781
function foo(bar:{a:number;}[]):string; function foo(bar:{a:boolean;}[]):number; function foo(bar:{a:any;}[]):any{ return bar }; var x1 = foo([{a:true}]); // works var x11 = foo([{a:0}]); // works var x111 = foo([{a:"s"}]); // error - does not match any signature var x1111 = foo([{a:null}]); // works - ambiguous call is resolved to be the first in the overload set so this returns a string function foo2(bar:{a:number;}):string; function foo2(bar:{a:boolean;}):number; function foo2(bar:{a:any;}):any{ return bar }; var x2 = foo2({a:0}); // works var x3 = foo2({a:true}); // works var x4 = foo2({a:"s"}); // error function foo4(bar:{a:number;}):number; function foo4(bar:{a:string;}):string; function foo4(bar:{a:any;}):any{ return bar }; var x = foo4({a:true}); // error
{ "end_byte": 781, "start_byte": 1, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/overloadResolutionTest1.ts" }
TypeScript/tests/cases/compiler/checkJsdocTypeTagOnExportAssignment7.ts_0_328
// @allowJs: true // @checkJs: true // @outDir: ./out // @filename: checkJsdocTypeTagOnExportAssignment7.js // @Filename: a.js /** * @typedef {Object} Foo * @property {number} a * @property {number} b */ const abc = { a: 1, b: 1, c: 1 }; /** @type {Foo} */ export default abc; // @Filename: b.js import a from "./a"; a;
{ "end_byte": 328, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkJsdocTypeTagOnExportAssignment7.ts" }
TypeScript/tests/cases/compiler/recursiveBaseConstructorCreation3.ts_0_194
declare class base<T> { } declare class abc<T> extends base<T> { foo: xyz; } declare class xyz extends abc { } var bar = new xyz(); // Error: Invalid 'new' expression. var r: xyz = bar.foo;
{ "end_byte": 194, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/recursiveBaseConstructorCreation3.ts" }
TypeScript/tests/cases/compiler/nonNullFullInference.ts_0_542
// @noImplicitAny: true // https://github.com/microsoft/TypeScript/issues/19577 function testNonNullInference(numbers: number[]) { let last; for (const n of numbers) { if (n % 2) { return n; } last = n; } last; last!; } function testNonNullInferenceWithArrays(numbers: number[]) { let result; const arr = []; for (const n of numbers) { if (n % 2) { return [n]; } arr.push(n); result = arr; } result; result!; }
{ "end_byte": 542, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nonNullFullInference.ts" }
TypeScript/tests/cases/compiler/ClassDeclaration11.ts_0_42
class C { constructor(); foo() { } }
{ "end_byte": 42, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ClassDeclaration11.ts" }
TypeScript/tests/cases/compiler/indexedAccessWithVariableElement.ts_0_453
// @strict: true // @noUncheckedIndexedAccess: true // @noEmit: true // repro from https://github.com/microsoft/TypeScript/issues/54420 declare const array1: [...number[], number] const el1: number = array1[0] declare const array2: [...number[], number] const el2: number = array2[1] declare const array3: [number, ...number[], number] const el3: number = array3[1] declare const array4: [number, ...number[], number] const el4: number = array4[2]
{ "end_byte": 453, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/indexedAccessWithVariableElement.ts" }
TypeScript/tests/cases/compiler/assignmentCompatability34.ts_0_359
module __test1__ { export interface interfaceWithPublicAndOptional<T,U> { one: T; two?: U; }; var obj4: interfaceWithPublicAndOptional<number,string> = { one: 1 };; export var __val__obj4 = obj4; } module __test2__ { export var obj: { <Tnumber>(a:Tnumber):Tnumber;}; export var __val__obj = obj; } __test2__.__val__obj = __test1__.__val__obj4
{ "end_byte": 359, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/assignmentCompatability34.ts" }
TypeScript/tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts_0_92
interface Test { readonly [key: string]: string; } declare var a: Test; a.foo = 'baz';
{ "end_byte": 92, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/propertyAccessOfReadonlyIndexSignature.ts" }
TypeScript/tests/cases/compiler/esModuleInteropDefaultMemberMustBeSyntacticallyDefaultExport.ts_0_283
// @esModuleInterop: true // @filename: point.d.ts declare class Point { x: number; y: number; constructor(x: number, y: number); static default: "foo"; } export = Point; // @filename: index.ts import Point from "./point"; const C = Point; const p = new C(1, 2);
{ "end_byte": 283, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/esModuleInteropDefaultMemberMustBeSyntacticallyDefaultExport.ts" }
TypeScript/tests/cases/compiler/selfRef.ts_0_276
// @lib: es5 module M { export class Test { private name = "hello"; public setName = function(value: string): void { (function () { name=value; })(); } public getName = function(): string { return name; } } }
{ "end_byte": 276, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/selfRef.ts" }
TypeScript/tests/cases/compiler/jsFileCompilationWithMapFileAsJsWithOutDir.ts_0_167
// @allowJs: true // @sourcemap: true // @outdir: out // @filename: a.ts class c { } // @filename: b.js.map function foo() { } // @filename: b.js function bar() { }
{ "end_byte": 167, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsFileCompilationWithMapFileAsJsWithOutDir.ts" }
TypeScript/tests/cases/compiler/pathsValidation4.ts_0_377
// @noTypesAndSymbols: true // @filename: tsconfig.json { "compilerOptions": { "traceResolution": true, "baseUrl": "./src", "paths": { "@interface/**/*" : ["./src/interface/*"], "@service/**/*": ["./src/service/**/*"], "@controller/*": ["controller/*"], } } } // @filename: src/main.ts import 'someModule';
{ "end_byte": 377, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/pathsValidation4.ts" }
TypeScript/tests/cases/compiler/unknownSymbols1.ts_0_476
var x = asdf; var y: asdf; function foo(x: asdf, y: number): asdf { } function foo2() { return asdf; } var z = <asdf>x; // should be an error class C<T> { foo: asdf; bar: C<asdf>; } class C2 implements asdf { } interface I extends adsf { } class C3 { constructor(x: any) { } } class C4 extends C3 { constructor() { super(asdf); } } var x2 = this.asdf; // no error, this is any class C5 { constructor() { this.asdf = asdf; } }
{ "end_byte": 476, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unknownSymbols1.ts" }
TypeScript/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts_0_107
// @declaration: true var [, , z] = [1, 2, 4]; var [, a, , ] = [3, 4, 5]; var [, , [, b, ]] = [3,5,[0, 1]];
{ "end_byte": 107, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitDestructuringArrayPattern5.ts" }
TypeScript/tests/cases/compiler/moduleResolutionWithExtensions_notSupported.ts_0_291
// @noImplicitReferences: true // @traceResolution: true // @Filename: /tsx.tsx // @Filename: /jsx.jsx // @Filename: /js.js // @Filename: /a.ts import tsx from "./tsx"; // Not allowed. import jsx from "./jsx"; // Not allowed. import js from "./js"; // OK because it's an untyped module.
{ "end_byte": 291, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleResolutionWithExtensions_notSupported.ts" }
TypeScript/tests/cases/compiler/recursiveConditionalCrash2.ts_0_293
// Simplified #43529 export type CanBeExpanded<T extends object> = { value: T } type Expand__<O, N, Depth> = N extends Depth ? unknown : O extends CanBeExpanded<any> ? Expand__<O['value'], N, Depth> : O export type UseQueryOptions<T> = Expand__<T, 4, 2>
{ "end_byte": 293, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/recursiveConditionalCrash2.ts" }
TypeScript/tests/cases/compiler/nestedUnaryExpressionHang.ts_0_34
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{ "end_byte": 34, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nestedUnaryExpressionHang.ts" }
TypeScript/tests/cases/compiler/noUncheckedIndexAccess.ts_0_528
//@noUncheckedIndexedAccess: true //@strictNullChecks: true enum Meat { Sausage, Bacon } const sausage = Meat.Sausage const valueSausage = Meat[sausage] const bacon = Meat.Bacon const valueBacon = Meat[bacon] const union: Meat.Bacon | Meat.Sausage = Meat.Bacon const valueUnion = Meat[union] //Avoiding a false positive const value = Meat[0] const valueUndefined = "testing" const value2 = Meat[valueUndefined] enum A { a, b, c } enum B { x, y, z } const value3 = A[B.x];
{ "end_byte": 528, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/noUncheckedIndexAccess.ts" }
TypeScript/tests/cases/compiler/checkJsTypeDefNoUnusedLocalMarked.ts_0_402
// @allowJs: true // @checkJs: true // @noEmit: true // @noUnusedLocals: true // @filename: file.ts class Foo { x: number; } declare global { var module: any; // Just here to remove unrelated error from test } export = Foo; // @filename: something.js /** @typedef {typeof import("./file")} Foo */ /** @typedef {(foo: Foo) => string} FooFun */ module.exports = /** @type {FooFun} */(void 0);
{ "end_byte": 402, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkJsTypeDefNoUnusedLocalMarked.ts" }
TypeScript/tests/cases/compiler/iterableTReturnTNext.ts_0_2548
// @target: esnext // @strict: true // @strictBuiltinIteratorReturn: * declare const map: Map<string, number>; declare const set: Set<number>; // based on: // - https://github.com/apollographql/apollo-client/blob/8740f198805a99e01136617c4055d611b92cc231/src/react/hooks/__tests__/useMutation.test.tsx#L2328 // - https://github.com/continuedev/continue/blob/046bca088a833f8b3620412ff64e4b6f41fbb959/extensions/vscode/src/autocomplete/lsp.ts#L60 const r1: number = map.values().next().value; // error when strictBuiltinIteratorReturn is true as result is potentially `{ done: true, value: undefined }` // based on: https://github.com/gcanti/fp-ts/blob/89a772e95e414acee679f42f56527606f7b61f30/src/Map.ts#L246 interface Next<A> { readonly done?: boolean readonly value: A } const r2: Next<number> = map.values().next(); // error when strictBuiltinIteratorReturn is true as result is potentially `{ done: true, value: undefined }` // based on: https://github.com/graphql/graphql-js/blob/e15c3ec4dc21d9fd1df34fe9798cadf3bf02c6ea/src/execution/__tests__/mapAsyncIterable-test.ts#L175 async function* source() { yield 1; yield 2; yield 3; } const doubles = source(); doubles.return(); // based on: https://github.com/backstage/backstage/blob/85d9346ef11c1c20e4405102b4f5d93afb1292c1/packages/core-app-api/src/routing/RouteTracker.tsx#L62 const r3: number | undefined = set.values().next().value; // based on: https://github.com/microsoft/TypeScript/blob/15f67e0b482faf9f6a3ab9965f3c11196bf3e99b/src/harness/compilerImpl.ts#L77 class MyMap implements Map<string, number> { declare private _keys: string[]; declare private _values: number[]; declare size: number; declare [Symbol.toStringTag]: string; clear(): void { } delete(key: string): boolean { return false; } forEach(callbackfn: (value: number, key: string, map: Map<string, number>) => void, thisArg?: any): void { } get(key: string): number | undefined { return undefined; } has(key: string): boolean { return false; } set(key: string, value: number): this { return this; } entries(): MapIterator<[string, number]> { throw new Error("Method not implemented."); } keys(): MapIterator<string> { throw new Error("Method not implemented."); } [Symbol.iterator](): MapIterator<[string, number]> { throw new Error("Method not implemented."); } // error when strictBuiltinIteratorReturn is true because values() has implicit `void` return, which isn't assignable to `undefined` * values() { yield* this._values; } }
{ "end_byte": 2548, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/iterableTReturnTNext.ts" }
TypeScript/tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts_3_3216
valid // no params () => 1; // one param, no type (arg) => 2; // one param, no type arg => 2; // one param, no type with default value (arg = 1) => 3; // one param, no type, optional (arg?) => 4; // typed param (arg: number) => 5; // typed param with default value (arg: number = 0) => 6; // optional param (arg?: number) => 7; // var arg param (...arg: number[]) => 8; // multiple arguments (arg1, arg2) => 12; (arg1 = 1, arg2 =3) => 13; (arg1?, arg2?) => 14; (arg1: number, arg2: number) => 15; (arg1: number = 0, arg2: number = 1) => 16; (arg1?: number, arg2?: number) => 17; (arg1, ...arg2: number[]) => 18; (arg1, arg2?: number) => 19; // in paren (() => 21); ((arg) => 22); ((arg = 1) => 23); ((arg?) => 24); ((arg: number) => 25); ((arg: number = 0) => 26); ((arg?: number) => 27); ((...arg: number[]) => 28); // in multiple paren (((((arg) => { return 32; })))); // in ternary exression false ? () => 41 : null; false ? (arg) => 42 : null; false ? (arg = 1) => 43 : null; false ? (arg?) => 44 : null; false ? (arg: number) => 45 : null; false ? (arg?: number) => 46 : null; false ? (arg?: number = 0) => 47 : null; false ? (...arg: number[]) => 48 : null; // in ternary exression within paren false ? (() => 51) : null; false ? ((arg) => 52) : null; false ? ((arg = 1) => 53) : null; false ? ((arg?) => 54) : null; false ? ((arg: number) => 55) : null; false ? ((arg?: number) => 56) : null; false ? ((arg?: number = 0) => 57) : null; false ? ((...arg: number[]) => 58) : null; // ternary exression's else clause false ? null : () => 61; false ? null : (arg) => 62; false ? null : (arg = 1) => 63; false ? null : (arg?) => 64; false ? null : (arg: number) => 65; false ? null : (arg?: number) => 66; false ? null : (arg?: number = 0) => 67; false ? null : (...arg: number[]) => 68; // nested ternary expressions ((a?) => { return a; }) ? (b? ) => { return b; } : (c? ) => { return c; }; //multiple levels (a?) => { return a; } ? (b)=>(c)=>81 : (c)=>(d)=>82; // In Expressions ((arg) => 90) instanceof Function; ((arg = 1) => 91) instanceof Function; ((arg? ) => 92) instanceof Function; ((arg: number) => 93) instanceof Function; ((arg: number = 1) => 94) instanceof Function; ((arg?: number) => 95) instanceof Function; ((...arg: number[]) => 96) instanceof Function; '' + ((arg) => 100); ((arg) => 0) + '' + ((arg) => 101); ((arg = 1) => 0) + '' + ((arg = 2) => 102); ((arg?) => 0) + '' + ((arg?) => 103); ((arg:number) => 0) + '' + ((arg:number) => 104); ((arg:number = 1) => 0) + '' + ((arg:number = 2) => 105); ((arg?:number = 1) => 0) + '' + ((arg?:number = 2) => 106); ((...arg:number[]) => 0) + '' + ((...arg:number[]) => 107); ((arg1, arg2?) => 0) + '' + ((arg1,arg2?) => 108); ((arg1, ...arg2:number[]) => 0) + '' + ((arg1, ...arg2:number[]) => 108); // Function Parameters function foo(...arg: any[]) { } foo( (a) => 110, ((a) => 111), (a) => { return 112; }, (a? ) => 113, (a, b? ) => 114, (a: number) => 115, (a: number = 0) => 116, (a = 0) => 117, (a?: number = 0) => 118, (...a: number[]) => 119, (a, b? = 0, ...c: number[]) => 120, (a) => (b) => (c) => 121, false? (a) => 0 : (b) => 122 );
{ "end_byte": 3216, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/fatarrowfunctionsOptionalArgs.ts" }
TypeScript/tests/cases/compiler/es5-asyncFunctionIfStatements.ts_0_310
// @lib: es5,es2015.promise // @noEmitHelpers: true // @target: ES5 declare var x, y, z, a, b, c; async function ifStatement1() { if (await x) { y; } else { z; } } async function ifStatement2() { if (x) { await y; } else { z; } } async function ifStatement3() { if (x) { y; } else { await z; } }
{ "end_byte": 310, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es5-asyncFunctionIfStatements.ts" }
TypeScript/tests/cases/compiler/errorWithTruncatedType.ts_0_379
// @noErrorTruncation: false var x: { propertyWithAnExceedinglyLongName1: string; propertyWithAnExceedinglyLongName2: string; propertyWithAnExceedinglyLongName3: string; propertyWithAnExceedinglyLongName4: string; propertyWithAnExceedinglyLongName5: string; }; // String representation of type of 'x' should be truncated in error message var s: string = x;
{ "end_byte": 379, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/errorWithTruncatedType.ts" }
TypeScript/tests/cases/compiler/divergentAccessorsTypes8.ts_0_2390
// @strict: true // @lib: esnext, dom // @noEmit: true export {} interface Serializer { set value(v: string | number | boolean); get value(): string; } declare let box: Serializer; const v = box['value'] box['value'] = true; box['value'] = 42; box['value'] = "hello"; interface Element { get style(): CSSStyleDeclaration; set style(cssText: string); } declare const element: Element; element['style'] = "color: red"; element['style'] = element.style; class One { get prop1(): string { return ""; } set prop1(s: string | number) {} get prop2(): string { return ""; } set prop2(s: string | number) {} prop3: number = 42; get prop4(): string { return ""; } set prop4(s: string | number) {} } class Two { get prop1(): string { return ""; } set prop1(s: string | number) {} get prop2(): string { return ""; } set prop2(s: string) {} get prop3(): string { return ""; } set prop3(s: string | boolean) {} get prop4(): string { return ""; } set prop4(s: string | boolean) {} } declare const u1: One | Two; u1['prop1'] = 42; u1['prop1'] = "hello"; u1['prop2'] = 42; u1['prop2'] = "hello"; u1['prop3'] = 42; u1['prop3'] = "hello"; u1['prop3'] = true; u1['prop4'] = 42; u1['prop4'] = "hello"; u1['prop4'] = true; declare const i: One & Two; const iv1 = i['prop1']; i['prop1'] = 42; i['prop1'] = "hello"; const iv2 = i['prop2']; i['prop2'] = 42; i['prop2'] = "hello"; class Three { get prop1(): string { return ""; } set prop1(s: string | number) {} prop2: number = 42; } class Four { get prop1(): "hello" { return "hello"; } set prop1(s: "hello" | number) {} get prop2(): string { return ""; } set prop2(s: string | 42) {} } class Five { get prop1(): "hello" { return "hello"; } set prop1(s: "hello" | boolean) {} get prop2(): string { return ""; } set prop2(s: string | number | boolean) {} } declare const i2: Three & Four & Five; i2['prop1'] = 42; i2['prop1'] = "hello"; i2['prop2'] = 42; i2['prop2'] = "hello"; class Six { get prop1(): boolean | number { return 42; } set prop1(s: boolean | string) {} get prop2(): bigint | number { return 10; } set prop2(s: boolean | null) {} } declare const s1: Six declare const k1: 'prop1' | 'prop2' const sv1 = s1[k1] s1[k1] = 42 s1[k1] = true s1[k1] = '' s1[k1] = null
{ "end_byte": 2390, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/divergentAccessorsTypes8.ts" }
TypeScript/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts_3_146
ass Base { constructor(...arg) { } } class Super extends Base { constructor() { var that = this; super(); } }
{ "end_byte": 146, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts" }
TypeScript/tests/cases/compiler/reactHOCSpreadprops.tsx_0_329
// @jsx: react // @strict: true /// <reference path="/.lib/react16.d.ts" /> import React = require("react"); function f<P>(App: React.ComponentClass<P> | React.StatelessComponent<P>): void { class C extends React.Component<P & { x: number }> { render() { return <App {...this.props} />; } } }
{ "end_byte": 329, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reactHOCSpreadprops.tsx" }
TypeScript/tests/cases/compiler/ExportAssignment7.ts_0_31
export class C { } export = B;
{ "end_byte": 31, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ExportAssignment7.ts" }
TypeScript/tests/cases/compiler/forLoopEndingMultilineComments.ts_0_359
declare var a: any; export function consoleTestResultHandler(testResult: any): boolean { // needed to get colors to show up when passing through Grunt void a; for (const q of a) { void a; /* eslint-disable no-console */ if (a) { } else { } /* eslint-enable no-console */ } return true; }
{ "end_byte": 359, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/forLoopEndingMultilineComments.ts" }
TypeScript/tests/cases/compiler/functionReturningItself.ts_0_62
// @declaration: true function somefn() { return somefn; }
{ "end_byte": 62, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionReturningItself.ts" }
TypeScript/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts_0_1024
// @module: amd // @traceResolution: true // @filename: c:/root/src/tsconfig.json { "compilerOptions": { "baseUrl": "../", "paths": { "*": [ "*", "c:/shared/*" ], "templates/*": [ "generated/src/templates/*" ] }, "rootDirs": [ ".", "../generated/src" ] } } // @filename: c:/root/src/file1.ts import {x} from "./project/file2"; import {y} from "module3"; declare function use(x: string); use(x.toFixed()); use(y.toFixed()); // @filename: c:/root/generated/src/project/file2.ts import {a} from "module1"; import {b} from "templates/module2"; import {x as c} from "../file3"; export let x = a + b + c; // @filename: c:/shared/module1.d.ts export let a: number // @filename: c:/root/generated/src/templates/module2.ts export let b: number; // @filename: c:/root/src/file3.d.ts export let x: number; // @filename: c:/module3.d.ts export let y: number;
{ "end_byte": 1024, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts" }
TypeScript/tests/cases/compiler/declFileTypeofEnum.ts_0_213
// @declaration: true enum days { monday, tuesday, wednesday, thursday, friday, saturday, sunday } var weekendDay = days.saturday; var daysOfMonth = days; var daysOfYear: typeof days;
{ "end_byte": 213, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declFileTypeofEnum.ts" }
TypeScript/tests/cases/compiler/es6ModuleLet.ts_0_358
// @target: ES6 export let a = "hello"; export let x: string = a, y = x; let b = y; let c: string = b, d = c; export module m1 { export let k = a; export let l: string = b, m = k; let n = m1.k; let o: string = n, p = k; } module m2 { export let k = a; export let l: string = b, m = k; let n = m1.k; let o: string = n, p = k; }
{ "end_byte": 358, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es6ModuleLet.ts" }
TypeScript/tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts_0_239
// @target: ES5 // @preserveConstEnums: true function foo1() { return E.A enum E { A } } function foo2() { return E.A const enum E { A } } const config = { a: AfterObject.A, }; const enum AfterObject { A = 2, }
{ "end_byte": 239, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts" }
TypeScript/tests/cases/compiler/slightlyIndirectedDeepObjectLiteralElaborations.ts_0_270
interface Foo { a: { b: { c: { d: string } } } } let q: Foo["a"] | undefined; const x: Foo = (void 0, { a: q = { b: ({ c: { d: 42 } }) } });
{ "end_byte": 270, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/slightlyIndirectedDeepObjectLiteralElaborations.ts" }
TypeScript/tests/cases/compiler/generics2NoError.ts_0_360
// @declaration: true interface A { a: string; } interface B extends A { b: string; } interface C extends B { c: string; } interface G<T, U extends B> { x: T; y: U; } var v1: { x: { a: string; } y: { a: string; b: string; c: string }; }; // Ok var v2: G<{ a: string }, C>; // Ok, equivalent to G<A, C> var v4: G<G<A, B>, C>; // Ok
{ "end_byte": 360, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/generics2NoError.ts" }
TypeScript/tests/cases/compiler/enumWithUnicodeEscape1.ts_0_27
enum E { 'gold \u2730' }
{ "end_byte": 27, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/enumWithUnicodeEscape1.ts" }
TypeScript/tests/cases/compiler/varArgsOnConstructorTypes.ts_0_434
//@module: amd export class A { constructor(ctor) { } } export class B extends A { private p1: number; private p2: string; constructor(element: any, url: string) { super(element); this.p1 = element; this.p2 = url; } } export interface I1 { register(inputClass: new(...params: any[]) => A); register(inputClass: { new (...params: any[]): A; }[]); } var reg: I1; reg.register(B);
{ "end_byte": 434, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/varArgsOnConstructorTypes.ts" }
TypeScript/tests/cases/compiler/unusedTypeParameters2.ts_0_179
//@noUnusedLocals:true //@noUnusedParameters:true class greeter<typeparameter1, typeparameter2> { private x: typeparameter2; public function1() { this.x; } }
{ "end_byte": 179, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedTypeParameters2.ts" }
TypeScript/tests/cases/compiler/genericCloneReturnTypes.ts_0_268
class Bar<T> { public size: number; public t: T; constructor(x: number) { this.size = x; } public clone() { return new Bar<T>(this.size); } } var b: Bar<number>; var b2 = b.clone(); var b3: Bar<string>; b = b2; b = b3;
{ "end_byte": 268, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericCloneReturnTypes.ts" }
TypeScript/tests/cases/compiler/tupleTypes.ts_0_1456
var v1: []; // Error var v2: [number]; var v3: [number, string]; var v4: [number, [string, string]]; var t: [number, string]; var t0 = t[0]; // number var t0: number; var t1 = t[1]; // string var t1: string; var t2 = t[2]; // number|string var t2: number|string; t = []; // Error t = [1]; // Error t = [1, "hello"]; // Ok t = ["hello", 1]; // Error t = [1, "hello", 2]; // Error var tf: [string, (x: string) => number] = ["hello", x => x.length]; declare function ff<T, U>(a: T, b: [T, (x: T) => U]): U; var ff1 = ff("hello", ["foo", x => x.length]); var ff1: number; function tuple2<T0, T1>(item0: T0, item1: T1): [T0, T1]{ return [item0, item1]; } var tt = tuple2(1, "string"); var tt0 = tt[0]; var tt0: number; var tt1 = tt[1]; var tt1: string; var tt2 = tt[2]; var tt2: number | string; tt = tuple2(1, undefined); tt = [1, undefined]; tt = [undefined, undefined]; tt = []; // Error var a: number[]; var a1: [number, string]; var a2: [number, number]; var a3: [number, {}]; a = a1; // Error a = a2; a = a3; // Error a1 = a2; // Error a1 = a3; // Error a3 = a1; a3 = a2; type B = Pick<[number], 'length'>; declare const b: B; b.length = 0; // Error declare const b1: readonly [number?]; b1.length = 0; // Error declare const b2: readonly [number, ...number[]]; b2.length = 0; // Error declare const b3: readonly number[]; b3.length = 0; // Error declare const b4: [number?]; b4.length = 0;
{ "end_byte": 1456, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/tupleTypes.ts" }
TypeScript/tests/cases/compiler/exportDefaultInterfaceAndValue.ts_0_100
export default interface A { a: string; } export default function() { return 1; } declare var x: A;
{ "end_byte": 100, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportDefaultInterfaceAndValue.ts" }
TypeScript/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts_0_260
// @noImplicitReturns: true declare function log(s: string): void; declare function get(): number; function main1() : number { try { return get(); } catch(e) { log("in catch"); } finally { log("in finally"); } }
{ "end_byte": 260, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts" }
TypeScript/tests/cases/compiler/inferringAnyFunctionType3.ts_0_97
function f<T extends ((p1: number) => number)[]>(p: T): T { return p; } var v = f([x => x]);
{ "end_byte": 97, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/inferringAnyFunctionType3.ts" }
TypeScript/tests/cases/compiler/moduleAugmentationDeclarationEmit1.ts_0_662
// @module: commonjs // @declaration: true // @filename: map.ts import { Observable } from "./observable" (<any>Observable.prototype).map = function() { } declare module "./observable" { interface Observable<T> { map<U>(proj: (e:T) => U): Observable<U> } namespace Observable { let someAnotherValue: number; } } // @filename: observable.ts export declare class Observable<T> { filter(pred: (e:T) => boolean): Observable<T>; } export namespace Observable { let someValue: number; } // @filename: main.ts import { Observable } from "./observable" import "./map"; let x: Observable<number>; let y = x.map(x => x + 1);
{ "end_byte": 662, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleAugmentationDeclarationEmit1.ts" }
TypeScript/tests/cases/compiler/callOverloads4.ts_1_309
function Foo():Foo; // error function Foo(s:string):Foo; // error class Foo { // error bar1() { /*WScript.Echo("bar1");*/ } constructor(s: string); constructor(x: any) { // WScript.Echo("Constructor function has executed"); } } var f1 = new Foo("hey"); f1.bar1(); Foo(); Foo("s");
{ "end_byte": 309, "start_byte": 1, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/callOverloads4.ts" }
TypeScript/tests/cases/compiler/illegalSuperCallsInConstructor.ts_0_389
class Base { x: string; } class Derived extends Base { constructor() { var r2 = () => super(); var r3 = () => { super(); } var r4 = function () { super(); } var r5 = { get foo() { super(); return 1; }, set foo(v: number) { super(); } } } }
{ "end_byte": 389, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/illegalSuperCallsInConstructor.ts" }
TypeScript/tests/cases/compiler/exportAsNamespace_augment.ts_0_393
// @Filename: /a.d.ts export as namespace a; export const x = 0; export const conflict = 0; // @Filename: /b.ts import * as a2 from "./a"; declare global { namespace a { export const y = 0; export const conflict = 0; } } declare module "./a" { export const z = 0; export const conflict = 0; } a.x + a.y + a.z + a.conflict; a2.x + a2.y + a2.z + a2.conflict;
{ "end_byte": 393, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportAsNamespace_augment.ts" }
TypeScript/tests/cases/compiler/transformParenthesizesConditionalSubexpression.ts_0_133
// @target: es5 var K = 'k' var a = { p : (true ? { [K] : 'v'} : null) } var b = { p : (true ? { [K] : 'v'} as any : null) }
{ "end_byte": 133, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/transformParenthesizesConditionalSubexpression.ts" }
TypeScript/tests/cases/compiler/implementClausePrecedingExtends.ts_0_58
class C { foo: number } class D implements C extends C { }
{ "end_byte": 58, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/implementClausePrecedingExtends.ts" }
TypeScript/tests/cases/compiler/unusedParametersinConstructor3.ts_0_181
//@noUnusedLocals:true //@noUnusedParameters:true class greeter { constructor(param1: string, param2: string, param3: string) { param2 = param2 + "dummy value"; } }
{ "end_byte": 181, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedParametersinConstructor3.ts" }
TypeScript/tests/cases/compiler/restParameterWithBindingPattern3.ts_0_302
function a(...[a = 1, b = true]: string[]) { } function b(...[...foo = []]: string[]) { } function c(...{0: a, length, 3: d}: [boolean, string, number]) { } function d(...[a, , , d]: [boolean, string, number]) { } function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { }
{ "end_byte": 302, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/restParameterWithBindingPattern3.ts" }
TypeScript/tests/cases/compiler/yieldInForInInDownlevelGenerator.ts_0_212
// @target: es5 // @lib: esnext // https://github.com/microsoft/TypeScript/issues/49808 function* gen() { var obj: any = { foo: 1, bar: 2 }; for (var key in obj) { yield key; delete obj.bar; } }
{ "end_byte": 212, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/yieldInForInInDownlevelGenerator.ts" }
TypeScript/tests/cases/compiler/objectLiteralPropertyImplicitlyAny.ts_0_107
// @target: esnext // @noImplicitAny: true const foo = Symbol.for("foo"); const o = { [foo]: undefined };
{ "end_byte": 107, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/objectLiteralPropertyImplicitlyAny.ts" }
TypeScript/tests/cases/compiler/jsFileCompilationLetDeclarationOrder.ts_0_139
// @allowJs: true // @outFile: out.js // @declaration: true // @filename: b.js let a = 10; b = 30; // @filename: a.ts let b = 30; a = 10;
{ "end_byte": 139, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsFileCompilationLetDeclarationOrder.ts" }
TypeScript/tests/cases/compiler/tslibNotFoundDifferentModules.ts_0_1798
// @filename: /tsconfig.json { "compilerOptions": { "strict": true, "target": "ES2016", "importHelpers": true, "module": "commonjs", } } // @filename: /package1/index.ts export {}; async function foo(): Promise<void> {} async function bar(): Promise<void> {} // @filename: /package1/node_modules/tslib/package.json { "name": "tslib", "main": "tslib.js", "typings": "tslib.d.ts" } // @filename: /package1/node_modules/tslib/tslib.d.ts /** * Converts a generator function into a pseudo-async function, by treating each `yield` as an `await`. * * @param thisArg The reference to use as the `this` value in the generator function * @param _arguments The optional arguments array * @param P The optional promise constructor argument, defaults to the `Promise` property of the global object. * @param generator The generator function */ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; // @filename: /package1/node_modules/tslib/tslib.js module.exports.__awaiter = function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; // @filename: /package2/index.ts export {}; async function foo(): Promise<void> {}
{ "end_byte": 1798, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/tslibNotFoundDifferentModules.ts" }
TypeScript/tests/cases/compiler/constraintsUsedInPrototypeProperty.ts_0_89
class Foo<T extends number, U, V extends string> { } Foo.prototype; // Foo<any, any, any>
{ "end_byte": 89, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/constraintsUsedInPrototypeProperty.ts" }
TypeScript/tests/cases/compiler/destructuringInitializerContextualTypeFromContext.ts_0_533
// @strict: true interface SFC<P = {}> { (props: P & { children?: any }): any | null; } interface Props { name: "Apollo" | "Artemis" | "Dionysus" | "Persephone"; } const Parent: SFC<Props> = ({ children, name = "Artemis", ...props }) => Child({name, ...props}); const Child: SFC<Props> = ({ children, name = "Artemis", ...props }) => `name: ${name} props: ${JSON.stringify(props)}`; // Repro from #29189 declare function f(g: (as: string[]) => void): void f(([_1, _2 = undefined]) => undefined)
{ "end_byte": 533, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/destructuringInitializerContextualTypeFromContext.ts" }
TypeScript/tests/cases/compiler/staticInstanceResolution5.ts_0_374
//@module: amd // @Filename: staticInstanceResolution5_0.ts export class Promise { static timeout(delay: number): Promise { return null; } } // @Filename: staticInstanceResolution5_1.ts import WinJS = require('staticInstanceResolution5_0'); // these 3 should be errors var x = (w1: WinJS) => { }; var y = function (w2: WinJS) { } function z(w3: WinJS) { }
{ "end_byte": 374, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/staticInstanceResolution5.ts" }
TypeScript/tests/cases/compiler/noImplicitReturnsExclusions.ts_0_2000
// @strict: true // @noImplicitReturns: true // @noEmit: true // Functions with a return type of any, undefined, or a type that includes void are excluded // from --noImplicitReturns checks. function f1(b: boolean): undefined { if (b) return undefined; } function f2(b: boolean): void { if (b) return undefined; } function f3(b: boolean): any { if (b) return undefined; } function f4(b: boolean): string | undefined { // Error if (b) return undefined; } function f5(b: boolean): string | void { if (b) return undefined; } function f6(b: boolean): unknown { // Error if (b) return undefined; } function f10(b: boolean) { if (b) return; } function f11(b: boolean) { if (b) return undefined; } function f12(b: boolean) { if (b) return undefined as any; } function f13(b: boolean) { // Error if (b) return undefined as unknown; } function f14(b: boolean) { // Error if (b) return 42; } function f15(b: boolean) { // Error if (b) return 42; if (b) return undefined; } function f16(b: boolean) { // Error if (b) return 42; if (b) return; } declare class HistoryItem { input: { location: { uri: string; }; }; } interface Thenable<T> { then<TResult>( onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult> ): Thenable<TResult>; then<TResult>( onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void ): Thenable<TResult>; } export declare function executeCommand<T = unknown>( command: string, ...rest: any[] ): Thenable<T>; export declare function registerCommand( command: string, callback: (...args: any[]) => any, thisArg?: any ): void; registerCommand("_references-view.showHistoryItem", async (item) => { // Error, contextual return type of Promise<unknown> if (item instanceof HistoryItem) { return executeCommand("vscode.open", item.input.location.uri); } });
{ "end_byte": 2000, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/noImplicitReturnsExclusions.ts" }
TypeScript/tests/cases/compiler/conditionalExpressionNewLine6.ts_0_23
var v = a ? b : c;
{ "end_byte": 23, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/conditionalExpressionNewLine6.ts" }
TypeScript/tests/cases/compiler/es5-system.ts_0_186
// @target: ES5 // @sourcemap: false // @declaration: false // @module: system export default class A { constructor () { } public B() { return 42; } }
{ "end_byte": 186, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es5-system.ts" }
TypeScript/tests/cases/compiler/mappedTypeNoTypeNoCrash.ts_0_100
// @declaration: true type T0<T> = ({[K in keyof T]}) extends ({[key in K]: T[K]}) ? number : never;
{ "end_byte": 100, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/mappedTypeNoTypeNoCrash.ts" }
TypeScript/tests/cases/compiler/noCollisionThisExpressionInFunctionAndVarInGlobal.ts_0_113
// @lib: es5 var console: { log(val: any); } var _this = 5; function x() { x => { console.log(this); }; }
{ "end_byte": 113, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/noCollisionThisExpressionInFunctionAndVarInGlobal.ts" }
TypeScript/tests/cases/compiler/classWithOverloadImplementationOfWrongName.ts_0_70
class C { foo(): string; foo(x): number; bar(x): any { } }
{ "end_byte": 70, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/classWithOverloadImplementationOfWrongName.ts" }
TypeScript/tests/cases/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.ts_0_828
// @strict: true // @allowJs: true // @checkJs: true // @noEmit: true // https://github.com/microsoft/TypeScript/issues/57460 // @filename: eslint-plugin-react.js const deprecatedRules = { "jsx-sort-default-props": true } const allRules = { 'no-unsafe': true } module.exports = { plugins: { react: { deprecatedRules, rules: allRules, }, }, }; // @Filename: typescript-eslint.js /** * @typedef {{ rules: Record<string, boolean> }} Plugin */ /** * @typedef {{ plugins: Record<string, Plugin> }} Config */ /** * @type {(...configs: Config[]) => void} */ function config(...configs) { } module.exports = { config }; // @Filename: eslint.config.js const eslintReact = require('./eslint-plugin-react.js'); const tseslint = require('./typescript-eslint.js'); tseslint.config(eslintReact)
{ "end_byte": 828, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.ts" }
TypeScript/tests/cases/compiler/invalidUseOfTypeAsNamespace.ts_0_47
interface OhNo { } declare let y: OhNo.hello;
{ "end_byte": 47, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/invalidUseOfTypeAsNamespace.ts" }
TypeScript/tests/cases/compiler/unusedImports13.ts_0_366
//@noUnusedLocals:true //@module: commonjs //@jsx: preserve // @filename: foo.tsx import React = require("react"); export const FooComponent = <div></div> // @filename: node_modules/@types/react/index.d.ts export = React; export as namespace React; declare namespace React { function createClass<P, S>(spec); } declare global { namespace JSX { } }
{ "end_byte": 366, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedImports13.ts" }
TypeScript/tests/cases/compiler/castOfAwait.ts_0_172
// @target: es6 async function f() { <number> await 0; typeof await 0; void await 0; await void <string> typeof <number> void await 0; await await 0; }
{ "end_byte": 172, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/castOfAwait.ts" }
TypeScript/tests/cases/compiler/checkJsFiles6.ts_0_80
// @allowJs: false // @checkJs: true // @noEmit: true // @fileName: a.js var x;
{ "end_byte": 80, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkJsFiles6.ts" }
TypeScript/tests/cases/compiler/unusedSetterInClass2.ts_0_192
// @noUnusedLocals:true // Unlike everything else, a setter without a getter is used by a write access. class Employee { private set p(_: number) {} m() { this.p = 0; } }
{ "end_byte": 192, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedSetterInClass2.ts" }
TypeScript/tests/cases/compiler/dottedNamesInSystem.ts_0_125
// @module: system export namespace A.B.C { export function foo() {} } export function bar() { return A.B.C.foo(); }
{ "end_byte": 125, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/dottedNamesInSystem.ts" }
TypeScript/tests/cases/compiler/es5ExportEquals.ts_0_97
// @target: es5 // @module: commonjs // @declaration: true export function f() { } export = f;
{ "end_byte": 97, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es5ExportEquals.ts" }
TypeScript/tests/cases/compiler/typeCheckExportsVariable.ts_1_35
let exports: number; exports = '';
{ "end_byte": 35, "start_byte": 1, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeCheckExportsVariable.ts" }
TypeScript/tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunction.ts_0_355
// @strict: true // @noEmit: true // repro from #52580 type Funcs<A, B extends Record<string, unknown>> = { [K in keyof B]: { fn: (a: A, b: B) => void; thing: B[K]; }; } declare function foo<A, B extends Record<string, unknown>>(fns: Funcs<A, B>): [A, B] const result = foo({ bar: { fn: (a: string) => {}, thing: 'asd', }, });
{ "end_byte": 355, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunction.ts" }
TypeScript/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts_0_147
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T; f10('', () => a => a.foo, ''); // a is "" var r9 = f10('', () => (a => a.foo), 1); // error
{ "end_byte": 147, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts" }
TypeScript/tests/cases/compiler/voidConstructor.ts_0_27
var foo:{ new ( ): void; }
{ "end_byte": 27, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/voidConstructor.ts" }
TypeScript/tests/cases/compiler/jsxFactoryQualifiedNameWithEs5.ts_0_271
//@module: commonjs //@target: es5 //@jsx: react //@jsxFactory: skate.h //@noEmit: false // @filename: index.tsx import "./jsx"; var skate: any; const React = { createElement: skate.h }; class Component { renderCallback() { return <div>test</div>; } };
{ "end_byte": 271, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxFactoryQualifiedNameWithEs5.ts" }
TypeScript/tests/cases/compiler/externalModuleExportingGenericClass.ts_0_355
// @module: commonjs // @Filename: externalModuleExportingGenericClass_file0.ts class C<T> { foo: T; } export = C; // @Filename: externalModuleExportingGenericClass_file1.ts import a = require('./externalModuleExportingGenericClass_file0'); var v: a; // this should report error var v2: any = (new a()).foo; var v3: number = (new a<number>()).foo;
{ "end_byte": 355, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/externalModuleExportingGenericClass.ts" }
TypeScript/tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunctionJs.ts_0_509
// @strict: true // @checkJs: true // @noEmit: true // @filename: index.js /** * @typedef {{ [K in keyof B]: { fn: (a: A, b: B) => void; thing: B[K]; } }} Funcs * @template A * @template {Record<string, unknown>} B */ /** * @template A * @template {Record<string, unknown>} B * @param {Funcs<A, B>} fns * @returns {[A, B]} */ function foo(fns) { return /** @type {any} */ (null); } const result = foo({ bar: { fn: /** @param {string} a */ (a) => {}, thing: "asd", }, });
{ "end_byte": 509, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunctionJs.ts" }
TypeScript/tests/cases/compiler/tryCatchFinallyControlFlow.ts_0_5344
// @strict: true // @allowUnreachableCode: false // Repro from #34797 function f1() { let a: number | null = null; try { a = 123; return a; } catch (e) { throw e; } finally { if (a != null && a.toFixed(0) == "123") { } } } function f2() { let x: 0 | 1 | 2 | 3 = 0; try { x = 1; } catch (e) { x = 2; throw e; } finally { x; // 0 | 1 | 2 } x; // 1 } function f3() { let x: 0 | 1 | 2 | 3 = 0; try { x = 1; } catch (e) { x = 2; return; } finally { x; // 0 | 1 | 2 } x; // 1 } function f4() { let x: 0 | 1 | 2 | 3 = 0; try { x = 1; } catch (e) { x = 2; } finally { x; // 0 | 1 | 2 } x; // 1 | 2 } function f5() { let x: 0 | 1 | 2 | 3 = 0; try { x = 1; return; } catch (e) { x = 2; } finally { x; // 0 | 1 | 2 } x; // 2 } function f6() { let x: 0 | 1 | 2 | 3 = 0; try { x = 1; } catch (e) { x = 2; return; } finally { x; // 0 | 1 | 2 } x; // 1 } function f7() { let x: 0 | 1 | 2 | 3 = 0; try { x = 1; return; } catch (e) { x = 2; return; } finally { x; // 0 | 1 | 2 } x; // Unreachable } function f8() { let x: 0 | 1 = 0; (() => { try { x = 1; return; } finally { x; // 0 | 1 } x; // Unreachable })(); x; // 1 } function f9() { let x: 0 | 1 | 2 = 0; (() => { try { if (!!true) { x = 1; return; } } finally { x; // 0 | 1 } x; // 0 x = 2; })(); x; // 1 | 2 } function f10() { let x: 0 | 1 | 2 | 3 = 0; (() => { try { x = 1; return; } catch (e) { x = 2; } finally { x; // 0 | 1 | 2 } x; // 2 x = 3; })(); x; // 1 | 3 } function f11() { let x: 0 | 1 | 2 | 3 | 4 | 5 = 0; (() => { try { if (!!true) { x = 1; return; } if (!!true) { x = 2; throw 0; } } catch (e) { x; // 0 | 1 | 2 x = 3; } finally { x; // 0 | 1 | 2 | 3 if (!!true) { x = 4; } } x; // 0 | 3 | 4 x = 5; })(); x; // 1 | 4 | 5 } function f12() { let x: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 = 0; (() => { try { if (!!true) { x = 1; return; } if (!!true) { x = 2; throw 0; } } catch (e) { x; // 0 | 1 | 2 x = 3; } finally { x; // 0 | 1 | 2 | 3 if (!!true) { x = 4; return; } if (!!true) { x = 5; return; } x = 6; return; x; // unreachable } x; // unreachable x = 7; // no effect })(); x; // 4 | 5 | 6 } // Repro from #35644 const main = () => { let hoge: string | undefined = undefined; try { hoge = 'hoge!'; return; } catch { return; } finally { if (hoge) { hoge.length; } return; } } // Repro from #36828 function t1() { const x = (() => { try { return 'x'; } catch (e) { return null; } x; // Unreachable })(); x; // Reachable } // Repro from #39043 type State = { tag: "one" } | { tag: "two" } | { tag: "three" }; function notallowed(arg: number) { let state: State = { tag: "one" }; try { state = { tag: "two" }; try { state = { tag: "three" }; } finally { } } catch (err) { state.tag; if (state.tag !== "one" && state.tag !== "two") { console.log(state.tag); } } } function f20() { let x: 0 | 1 | 2 | 3 | 4 | 5 | 6 = 0; try { x = 1; try { x = 2; try { x = 3; } finally { if (!!true) x = 4; } x; // 3 | 4 } finally { if (!!true) x = 5; } x; // 3 | 4 | 5 } finally { if (!!true) x = 6; } x; // 3 | 4 | 5 | 6 } function f21() { let x: 0 | 1 | 2 | 3 | 4 | 5 = 0; try { x = 1; try { x = 2; try { x = 3; } finally { if (!!true) x = 4; } x; // 3 | 4 } finally { if (!!true) x = 5; } x; // 3 | 4 | 5 } catch (e) { x; // 0 | 1 | 2 | 3 | 4 | 5 } }
{ "end_byte": 5344, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/tryCatchFinallyControlFlow.ts" }