_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
TypeScript/tests/cases/compiler/superInObjectLiterals_ES5.ts_0_1058
// @target: ES5 var obj = { __proto__: { method() { } }, method() { super.method(); }, get prop() { super.method(); return 10; }, set prop(value) { super.method(); }, p1: function () { super.method(); }, p2: function f() { super.method(); }, p3: () => { super.method(); } }; class A { method() { } } class B extends A { f() { var obj = { __proto__: { method() { } }, method() { super.method(); }, get prop() { super.method(); return 10; }, set prop(value) { super.method(); }, p1: function () { super.method(); }, p2: function f() { super.method(); }, p3: () => { super.method(); } }; } }
{ "end_byte": 1058, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/superInObjectLiterals_ES5.ts" }
TypeScript/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.ts_0_455
// @noImplicitReferences: true // @traceResolution: true // @allowJs: true // @filename: /foo.ts export function foo() {} // @filename: /bar.js export function bar() {} // @filename: /root/a.ts import { foo } from "/foo"; import { bar } from "/bar"; // @filename: /root/tsconfig.json { "compilerOptions": { "baseUrl": ".", "paths": { "*": ["./src/*"] }, "allowJs": true, "outDir": "bin" } }
{ "end_byte": 455, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.ts" }
TypeScript/tests/cases/compiler/getAndSetNotIdenticalType3.ts_0_211
class A<T> { foo: T; } class C<T> { data: A<number>; get x(): A<number> { return this.data; } set x(v: A<string>) { this.data = v; } } var x = new C(); var r = x.x; x.x = r;
{ "end_byte": 211, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/getAndSetNotIdenticalType3.ts" }
TypeScript/tests/cases/compiler/classImplementingInterfaceIndexer.ts_0_100
interface I { [index: string]: { prop } } class A implements I { [index: string]: { prop } }
{ "end_byte": 100, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/classImplementingInterfaceIndexer.ts" }
TypeScript/tests/cases/compiler/sourceMapValidationWhile.ts_0_89
// @sourcemap: true var a = 10; while (a == 10) { a++; } while (a == 10) { a++; }
{ "end_byte": 89, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/sourceMapValidationWhile.ts" }
TypeScript/tests/cases/compiler/genericReduce.ts_0_686
var a = ["An", "array", "of", "strings"]; var b = a.map(s => s.length); var n1 = b.reduce((x, y) => x + y); var n2 = b.reduceRight((x, y) => x + y); n1.x = "fail"; // should error, as 'n1' should be type 'number', not 'any'. n1.toExponential(2); // should not error if 'n1' is correctly number. n2.x = "fail"; // should error, as 'n2' should be type 'number', not 'any'. n2.toExponential(2); // should not error if 'n2' is correctly number. var n3 = b.reduce<string>( (x, y) => x + y, ""); // Initial value is of type string n3.toExponential(2); // should error if 'n3' is correctly type 'string' n3.charAt(0); // should not error if 'n3' is correctly type 'string'
{ "end_byte": 686, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericReduce.ts" }
TypeScript/tests/cases/compiler/checkDestructuringShorthandAssigment.ts_0_175
// @allowjs: true // @checkjs: true // @noEmit: true // @Filename: bug25434.js // should not crash while checking function Test({ b = '' } = {}) {} Test(({ b = '5' } = {}));
{ "end_byte": 175, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkDestructuringShorthandAssigment.ts" }
TypeScript/tests/cases/compiler/crashOnMethodSignatures.ts_0_47
class A { a(completed: () => any): void; }
{ "end_byte": 47, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/crashOnMethodSignatures.ts" }
TypeScript/tests/cases/compiler/nullKeyword.ts_0_9
null.foo;
{ "end_byte": 9, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nullKeyword.ts" }
TypeScript/tests/cases/compiler/assignmentCompatability15.ts_0_339
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 = {two: true}; export var __val__obj = obj; } __test2__.__val__obj = __test1__.__val__obj4
{ "end_byte": 339, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/assignmentCompatability15.ts" }
TypeScript/tests/cases/compiler/internalImportUnInstantiatedModuleNotReferencingInstanceNoConflict.ts_0_97
module A { export interface X { s: string } } module B { var A = 1; import Y = A; }
{ "end_byte": 97, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/internalImportUnInstantiatedModuleNotReferencingInstanceNoConflict.ts" }
TypeScript/tests/cases/compiler/commentsArgumentsOfCallExpression2.ts_3_335
nction foo(/*c1*/ x: any, /*d1*/ y: any,/*e1*/w?: any) { } var a, b: any; foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b); foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); foo( /*c4*/ function () { }, /*d4*/() => { }, /*e4*/ /*e5*/ "hello");
{ "end_byte": 335, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/commentsArgumentsOfCallExpression2.ts" }
TypeScript/tests/cases/compiler/classTypeParametersInStatics.ts_0_879
module Editor { export class List<T> { public next: List<T>; public prev: List<T>; constructor(public isHead: boolean, public data: T) { } public static MakeHead(): List<T> { // should error var entry: List<T> = new List<T>(true, null); entry.prev = entry; entry.next = entry; return entry; } public static MakeHead2<T>(): List<T> { // should not error var entry: List<T> = new List<T>(true, null); entry.prev = entry; entry.next = entry; return entry; } public static MakeHead3<U>(): List<U> { // should not error var entry: List<U> = new List<U>(true, null); entry.prev = entry; entry.next = entry; return entry; } } }
{ "end_byte": 879, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/classTypeParametersInStatics.ts" }
TypeScript/tests/cases/compiler/overloadOnGenericClassAndNonGenericClass.ts_0_254
class A { a; } class B { b; } class C { c; } class X<T> { x: T; } class X1 { x: string; } class X2 { x: string; } function f(a: X1): A; function f<T>(a: X<T>): B; function f(a): any { } var xs: X<string>; var t3 = f(xs); var t3: A; // should not error
{ "end_byte": 254, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/overloadOnGenericClassAndNonGenericClass.ts" }
TypeScript/tests/cases/compiler/functionCall5.ts_0_102
module m1 { export class c1 { public a; }} function foo():m1.c1{return new m1.c1();}; var x = foo();
{ "end_byte": 102, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionCall5.ts" }
TypeScript/tests/cases/compiler/aliasUsageInOrExpression.ts_0_933
// @module: commonjs // @Filename: aliasUsageInOrExpression_backbone.ts export class Model { public someData: string; } // @Filename: aliasUsageInOrExpression_moduleA.ts import Backbone = require("./aliasUsageInOrExpression_backbone"); export class VisualizationModel extends Backbone.Model { // interesting stuff here } // @Filename: aliasUsageInOrExpression_main.ts import Backbone = require("./aliasUsageInOrExpression_backbone"); import moduleA = require("./aliasUsageInOrExpression_moduleA"); interface IHasVisualizationModel { VisualizationModel: typeof Backbone.Model; } var i: IHasVisualizationModel; var d1 = i || moduleA; var d2: IHasVisualizationModel = i || moduleA; var d2: IHasVisualizationModel = moduleA || i; var e: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null || { x: moduleA }; var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x: moduleA } : null;
{ "end_byte": 933, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/aliasUsageInOrExpression.ts" }
TypeScript/tests/cases/compiler/collisionExportsRequireAndVar.ts_0_527
//@module: amd //@filename: collisionExportsRequireAndVar_externalmodule.ts export function foo() { } var exports = 1; var require = "require"; module m1 { var exports = 0; var require = "require"; } module m2 { export var exports = 0; export var require = "require"; } //@filename: collisionExportsRequireAndVar_globalFile.ts var exports = 0; var require = "require"; module m3 { var exports = 0; var require = "require"; } module m4 { export var exports = 0; export var require = "require"; }
{ "end_byte": 527, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/collisionExportsRequireAndVar.ts" }
TypeScript/tests/cases/compiler/functionOverloads3.ts_0_22
function foo():string;
{ "end_byte": 22, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionOverloads3.ts" }
TypeScript/tests/cases/compiler/fatarrowfunctionsErrors.ts_0_279
foo((...Far:any[])=>{return 0;}) foo((1)=>{return 0;}); foo((x?)=>{return x;}) foo((x=0)=>{return x;}) var y = x:number => x*x; false? (() => null): null; // missing fatarrow var x1 = () :void {}; var x2 = (a:number) :void {}; var x3 = (a:number) {}; var x4= (...a: any[]) { };
{ "end_byte": 279, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/fatarrowfunctionsErrors.ts" }
TypeScript/tests/cases/compiler/partialTypeNarrowedToByTypeGuard.ts_0_379
// @strict: true type Obj = {} | undefined; type User = { email: string; name: string; }; type PartialUser = Partial<User>; // type PartialUser = { // email?: string; // name?: string; // }; function isUser(obj: Obj): obj is PartialUser { return true; } function getUserName(obj: Obj) { if (isUser(obj)) { return obj.name; } return ''; }
{ "end_byte": 379, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/partialTypeNarrowedToByTypeGuard.ts" }
TypeScript/tests/cases/compiler/circularInstantiationExpression.ts_0_77
// @declaration: true declare function foo<T>(t: T): typeof foo<T>; foo("");
{ "end_byte": 77, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/circularInstantiationExpression.ts" }
TypeScript/tests/cases/compiler/modularizeLibrary_Worker.iterable.ts_3_143
@skipLibCheck: true // @lib: es6,webworker,webworker.iterable // @target: es6 for (const [key, entry] of new FormData()) { entry; }
{ "end_byte": 143, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/modularizeLibrary_Worker.iterable.ts" }
TypeScript/tests/cases/compiler/preserveUnusedImports.ts_0_196
// @importsNotUsedAsValues: preserve // @Filename: a.ts export type A = {}; // @Filename: b.ts export class B {} // @Filename: c.ts import { A } from './a'; import { B } from './b'; let b: B;
{ "end_byte": 196, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/preserveUnusedImports.ts" }
TypeScript/tests/cases/compiler/tsconfigExtendsPackageJsonExportsWildcard.ts_0_435
// @noTypesAndSymbols: true // @noEmit: true // @Filename: /node_modules/foo/package.json { "name": "foo", "version": "1.0.0", "exports": { "./*.json": "./configs/*.json" } } // @Filename: /node_modules/foo/configs/strict.json { "compilerOptions": { "strict": true } } // @Filename: /tsconfig.json { "extends": "foo/strict.json" } // @Filename: /index.ts let x: string; x.toLowerCase();
{ "end_byte": 435, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/tsconfigExtendsPackageJsonExportsWildcard.ts" }
TypeScript/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts_3_162
@target: ES6 class A { blub = 6; } class B extends A { blub = 12; constructor() { 'someStringForEgngInject'; super() } }
{ "end_byte": 162, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/emitSuperCallBeforeEmitPropertyDeclaration1ES6.ts" }
TypeScript/tests/cases/compiler/conditionalTypeSimplification.ts_0_373
// Repro from #30794 interface AbstractSchema<S, V> { m1<T> (v: T): SchemaType<S, Exclude<V, T>>; m2<T> (v: T): SchemaType<S, T>; } type SchemaType<S, V> = S extends object ? AnySchema<V> : never; interface AnySchema<V> extends AnySchemaType<AnySchema<undefined>, V> { } interface AnySchemaType<S extends AbstractSchema<any, any>, V> extends AbstractSchema<S, V> { }
{ "end_byte": 373, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/conditionalTypeSimplification.ts" }
TypeScript/tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts_0_248
declare module "OuterModule" { import m2 = require("./SubModule"); class SubModule { public static StaticVar: number; public InstanceVar: number; public x: m2.c; constructor(); } export = SubModule; }
{ "end_byte": 248, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts" }
TypeScript/tests/cases/compiler/mappedTypeParameterConstraint.ts_0_121
// Repro for #27596 type MyMap<T> = {[P in keyof T]: T[keyof T]}; function foo<U>(arg: U): MyMap<U> { return arg; }
{ "end_byte": 121, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/mappedTypeParameterConstraint.ts" }
TypeScript/tests/cases/compiler/copyrightWithNewLine1.ts_0_254
// @module: amd /***************************** * (c) Copyright - Important ****************************/ import model = require("./greeter") var el = document.getElementById('content'); var greeter = new model.Greeter(el); /** things */ greeter.start();
{ "end_byte": 254, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/copyrightWithNewLine1.ts" }
TypeScript/tests/cases/compiler/exportDefaultInterfaceClassAndValue.ts_0_93
const foo = 1 export default foo export default class Foo {} export default interface Foo {}
{ "end_byte": 93, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportDefaultInterfaceClassAndValue.ts" }
TypeScript/tests/cases/compiler/errorsForCallAndAssignmentAreSimilar.ts_0_304
function minimalExample1() { type Disc = | { kind: "hddvd" } | { kind: "bluray" } function foo(x: Disc[]) { } foo([ { kind: "bluray", }, { kind: "hdpvd", } ]); const ds: Disc[] = [ { kind: "bluray", }, { kind: "hdpvd", } ]; }
{ "end_byte": 304, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/errorsForCallAndAssignmentAreSimilar.ts" }
TypeScript/tests/cases/compiler/convertClassExpressionToFunctionFromObjectProperty2.ts_0_4126
// @target: es5 ({ x: class { constructor() { } }, y: class { constructor() { } }, // keywords break: class { constructor() { } }, case: class { constructor() { } }, catch: class { constructor() { } }, class: class { constructor() { } }, const: class { constructor() { } }, continue: class { constructor() { } }, debugger: class { constructor() { } }, default: class { constructor() { } }, delete: class { constructor() { } }, do: class { constructor() { } }, else: class { constructor() { } }, enum: class { constructor() { } }, export: class { constructor() { } }, extends: class { constructor() { } }, false: class { constructor() { } }, finally: class { constructor() { } }, for: class { constructor() { } }, function: class { constructor() { } }, if: class { constructor() { } }, import: class { constructor() { } }, in: class { constructor() { } }, instanceof: class { constructor() { } }, new: class { constructor() { } }, null: class { constructor() { } }, return: class { constructor() { } }, super: class { constructor() { } }, switch: class { constructor() { } }, this: class { constructor() { } }, throw: class { constructor() { } }, true: class { constructor() { } }, try: class { constructor() { } }, typeof: class { constructor() { } }, var: class { constructor() { } }, void: class { constructor() { } }, while: class { constructor() { } }, with: class { constructor() { } }, implements: class { constructor() { } }, interface: class { constructor() { } }, let: class { constructor() { } }, package: class { constructor() { } }, private: class { constructor() { } }, protected: class { constructor() { } }, public: class { constructor() { } }, static: class { constructor() { } }, yield: class { constructor() { } }, abstract: class { constructor() { } }, as: class { constructor() { } }, asserts: class { constructor() { } }, any: class { constructor() { } }, async: class { constructor() { } }, await: class { constructor() { } }, boolean: class { constructor() { } }, constructor: class { constructor() { } }, declare: class { constructor() { } }, get: class { constructor() { } }, infer: class { constructor() { } }, is: class { constructor() { } }, keyof: class { constructor() { } }, module: class { constructor() { } }, namespace: class { constructor() { } }, never: class { constructor() { } }, readonly: class { constructor() { } }, require: class { constructor() { } }, number: class { constructor() { } }, object: class { constructor() { } }, set: class { constructor() { } }, string: class { constructor() { } }, symbol: class { constructor() { } }, type: class { constructor() { } }, undefined: class { constructor() { } }, unique: class { constructor() { } }, unknown: class { constructor() { } }, from: class { constructor() { } }, global: class { constructor() { } }, bigint: class { constructor() { } }, of: class { constructor() { } } })
{ "end_byte": 4126, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/convertClassExpressionToFunctionFromObjectProperty2.ts" }
TypeScript/tests/cases/compiler/mappedTypeGenericWithKnownKeys.ts_0_339
// @noEmit: true // @strict: true // based on #50054 function test<Shape extends Record<string, string>>(shape: Shape, key: keyof Shape) { const obj = {} as Record<keyof Shape | "knownLiteralKey", number>; obj.knownLiteralKey = 1; obj[key] = 2; obj.unknownLiteralKey = 3; // error obj['' as string] = 4; // error }
{ "end_byte": 339, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/mappedTypeGenericWithKnownKeys.ts" }
TypeScript/tests/cases/compiler/assignmentCompatability21.ts_0_340
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 = {two: ["1"]}; export var __val__obj = obj; } __test2__.__val__obj = __test1__.__val__obj4
{ "end_byte": 340, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/assignmentCompatability21.ts" }
TypeScript/tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts_0_229
// @strict: true // @noEmit: true // https://github.com/microsoft/TypeScript/issues/59062 function f<_T, _S>() { interface NumArray<T extends number> extends Array<T> {} type X = NumArray<X extends {} ? number : number>; }
{ "end_byte": 229, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts" }
TypeScript/tests/cases/compiler/reactImportUnusedInNewJSXEmit.tsx_0_284
// @esModuleInterop: true // @noUnusedLocals: true // @jsx: react-jsx,react-jsxdev // @skipLibCheck: true // @filename: index.tsx /// <reference path="/.lib/react16.d.ts" /> import React from "react"; function Bar() { return <div />; } export function Foo() { return <Bar />; }
{ "end_byte": 284, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reactImportUnusedInNewJSXEmit.tsx" }
TypeScript/tests/cases/compiler/importAndVariableDeclarationConflict1.ts_0_63
module m { export var m = ''; } import x = m.m; var x = '';
{ "end_byte": 63, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/importAndVariableDeclarationConflict1.ts" }
TypeScript/tests/cases/compiler/overloadOnConstInheritance4.ts_0_198
interface I { x1(a: number, callback: (x: 'hi') => number); } class C implements I { x1(a: number, callback: (x: 'hi') => number); x1(a: number, callback: (x: 'hi') => number) { } }
{ "end_byte": 198, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/overloadOnConstInheritance4.ts" }
TypeScript/tests/cases/compiler/internalAliasInterfaceInsideLocalModuleWithoutExportAccessError.ts_0_140
//@module: amd export module a { export interface I { } } export module c { import b = a.I; export var x: b; } var x: c.b;
{ "end_byte": 140, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/internalAliasInterfaceInsideLocalModuleWithoutExportAccessError.ts" }
TypeScript/tests/cases/compiler/classDeclaredBeforeClassFactory.ts_0_129
// Should be OK due to hoisting class Derived extends makeBaseClass() {} function makeBaseClass() { return class Base {}; }
{ "end_byte": 129, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/classDeclaredBeforeClassFactory.ts" }
TypeScript/tests/cases/compiler/interfaceMayNotBeExtendedWitACall.ts_0_65
interface color {} interface blue extends color() { // error }
{ "end_byte": 65, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/interfaceMayNotBeExtendedWitACall.ts" }
TypeScript/tests/cases/compiler/substitutionTypeForIndexedAccessType1.ts_0_161
type AddPropToObject<Obj extends object, Prop extends string> = Prop extends keyof Obj ? Obj[Prop] extends unknown[] ? [...Obj[Prop]] : never : never
{ "end_byte": 161, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/substitutionTypeForIndexedAccessType1.ts" }
TypeScript/tests/cases/compiler/generics4NoError.ts_0_136
// @declaration: true class C<T> { private x: T; } interface X { f(): string; } interface Y { f(): boolean; } var a: C<X>; var b: C<Y>;
{ "end_byte": 136, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/generics4NoError.ts" }
TypeScript/tests/cases/compiler/literalFreshnessPropagationOnNarrowing.ts_0_1302
function f1() { let b = true; let obj = { b }; // Desired: OK // 3.0: OK // 3.1 as-is: OK // 3.1 minus widening propagation: error obj.b = false; } function f2() { type Element = (string | false); type ElementOrArray = Element | Element[]; let el: Element = null as any; let arr: Element[] = null as any; let elOrA: ElementOrArray = null as any; // Desired/actual: All OK let a1: ElementOrArray = el; let a2: ElementOrArray = arr; let a3: ElementOrArray = [el]; let a4: ElementOrArray = Array.isArray(elOrA) ? elOrA : [elOrA]; // Desired: OK // 3.0: Error // 3.1: OK let a5: ElementOrArray = [...Array.isArray(elOrA) ? elOrA : [elOrA]]; } function f3() { type XY = 'x' | 'y'; const x: XY = 'x'; let x2 = x; // Desired: OK (up for debate?) // 3.0: Error // 3.1 as-is: OK x2 = 'y'; // Desired/actual: All OK let x3: XY = x; x3 = 'y'; } function f4() { const x: boolean = true; let x1 = x; // Desired: OK // 3.0: OK // 3.1: OK // 3.1 minus widening propagation: error x1 = false; } function f5() { type XY = 'x' | 'y'; let arr: XY[] = ['x']; arr = ['y']; // Desired: OK // Error in all extant branches arr = [...['y']]; }
{ "end_byte": 1302, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/literalFreshnessPropagationOnNarrowing.ts" }
TypeScript/tests/cases/compiler/superWithTypeArgument.ts_0_88
class C { } class D<T> extends C { constructor() { super<T>(); } }
{ "end_byte": 88, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/superWithTypeArgument.ts" }
TypeScript/tests/cases/compiler/capturedLetConstInLoop2_ES6.ts_0_3411
// @target: ES6 // ========let function foo0(x) { for (let x of []) { let a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo0_1(x) { for (let x in []) { let a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo1(x) { for (let x = 0; x < 1; ++x) { let a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo2(x) { while (1 === 1) { let a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo3(x) { do { let x; let a = arguments.length; (function() { return x + a }); (() => x + a); } while (1 === 1) } function foo4(x) { for (let y = 0; y < 1; ++y) { let a = arguments.length; let x = 1; (function() { return x + a }); (() => x + a); } } function foo5(x) { for (let x = 0, y = 1; x < 1; ++x) { let a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } } function foo6(x) { while (1 === 1) { let x, y; let a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } } function foo7(x) { do { let x, y; let a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } while (1 === 1) } function foo8(x) { for (let y = 0; y < 1; ++y) { let x = 1; let a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } } ///=======const function foo0_c(x) { for (const x of []) { const a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo0_1_c(x) { for (const x in []) { const a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo1_c(x) { for (const x = 0; x < 1;) { const a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo2_c(x) { while (1 === 1) { const a = arguments.length; (function() { return x + a }); (() => x + a); } } function foo3_c(x) { do { const x = 1; const a = arguments.length; (function() { return x + a }); (() => x + a); } while (1 === 1) } function foo4_c(x) { for (const y = 0; y < 1;) { const a = arguments.length; const x = 1; (function() { return x + a }); (() => x + a); } } function foo5_c(x) { for (const x = 0, y = 1; x < 1;) { const a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } } function foo6_c(x) { while (1 === 1) { const x = 1, y =1 ; const a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } } function foo7_c(x) { do { const x = 1, y = 1; const a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } while (1 === 1) } function foo8_c(x) { for (const y = 0; y < 1;) { const x = 1; const a = arguments.length; (function() { return x + y + a }); (() => x + y + a); } }
{ "end_byte": 3411, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/capturedLetConstInLoop2_ES6.ts" }
TypeScript/tests/cases/compiler/noImplicitAnyMissingSetAccessor.ts_3_188
@noImplicitAny: true // @target: es5 abstract class Parent { public abstract get message(); } class Child extends Parent { public get message() { return ""; } }
{ "end_byte": 188, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/noImplicitAnyMissingSetAccessor.ts" }
TypeScript/tests/cases/compiler/singletonLabeledTuple.ts_0_832
type AliasOptional = [p?: number] // literal type vs type alias type Literal = [p?: number] extends [unknown] ? true : false // Expect `Literal` to be `false` type Alias = AliasOptional extends [unknown] ? true : false // Expect `Alias` to be `false` // labeled tuple vs normal tuple type Labeled = [p?: number] extends [unknown] ? true : false // Expect `Labeled` to be `false` type Normal = [number?] extends [unknown] ? true : false // Expect `Normal` to be `false` type AliasRest = [...p: number[]]; type LiteralRest = [...p: number[]] extends [unknown] ? true : false; // Expect `LiteralRest` to be `false` type AliasedRest = AliasRest extends [unknown] ? true : false; // Expect `AliasedRest` to be `false` type NormalRest = [...number[]] extends [unknown] ? true : false; // Expect `NormalRest` to be `false`
{ "end_byte": 832, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/singletonLabeledTuple.ts" }
TypeScript/tests/cases/compiler/elidedJSImport2.ts_0_593
// @allowJs: true // @checkJs: false // @module: ES2022, commonjs // @moduleResolution: node16 // @esModuleInterop: true // @isolatedModules: true // @outDir: out // @Filename: index.js import { Foo } from "./other.js"; import * as other from "./other.js"; import defaultFoo from "./other.js"; const x = new Foo(); const y = other.Foo(); const z = new defaultFoo(); // @Filename: other.d.ts export interface Foo { bar: number; } export default interface Bar { foo: number; } // @Filename: other.js export class Foo { bar = 2.4; } export default class Bar { foo = 1.2; }
{ "end_byte": 593, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/elidedJSImport2.ts" }
TypeScript/tests/cases/compiler/staticInheritance.ts_0_192
function doThing(x: { n: string }) { } class A { static n: string; p = doThing(A); // OK } class B extends A { p1 = doThing(A); // OK p2 = doThing(B); // OK } doThing(B); //OK
{ "end_byte": 192, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/staticInheritance.ts" }
TypeScript/tests/cases/compiler/unusedFunctionsinNamespaces5.ts_0_246
//@noUnusedLocals:true //@noUnusedParameters:true namespace Validation { var function1 = function() { } export function function2() { } function function3() { function1(); } function function4() { } }
{ "end_byte": 246, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedFunctionsinNamespaces5.ts" }
TypeScript/tests/cases/compiler/dissallowSymbolAsWeakType.ts_0_350
// @lib: es2022 // @target: es2022 const s: symbol = Symbol('s'); const ws = new WeakSet([s]); ws.add(s); ws.has(s); ws.delete(s); const wm = new WeakMap([[s, false]]); wm.set(s, true); wm.has(s); wm.get(s); wm.delete(s); const wr = new WeakRef(s); wr.deref(); const f = new FinalizationRegistry(() => {}); f.register(s, null); f.unregister(s);
{ "end_byte": 350, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/dissallowSymbolAsWeakType.ts" }
TypeScript/tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts_0_127
// @module: commonjs // @declaration: true // @noEmitOnError: true type T = { x : number } export interface I { f: T; }
{ "end_byte": 127, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts" }
TypeScript/tests/cases/compiler/inlineMappedTypeModifierDeclarationEmit.ts_0_921
// @declaration: true // @filename: index.ts import { test1, test2 } from "./other"; export function wrappedTest1<T, K extends string>(obj: T, k: K) { return test1(obj, k); } export function wrappedTest2<T, K extends string>(obj: T, k: K) { return test2(obj, k); } export type Obj = { a: number; readonly foo: string; }; export const processedInternally1 = wrappedTest1({} as Obj, "a"); export const processedInternally2 = wrappedTest2({} as Obj, "a"); // @filename: other.ts // how Omit from lib is defined type OmitReal<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>; // what we see when we hover it type OmitUnveiled<T, K extends string | number | symbol> = { [P in Exclude<keyof T, K>]: T[P]; }; export function test1<T, K extends string>(obj: T, k: K): OmitReal<T, K> { return {} as any; } export function test2<T, K extends string>(obj: T, k: K): OmitUnveiled<T, K> { return {} as any; }
{ "end_byte": 921, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/inlineMappedTypeModifierDeclarationEmit.ts" }
TypeScript/tests/cases/compiler/arrayReferenceWithoutTypeArgs.ts_0_38
class X { public f(a: Array) { } }
{ "end_byte": 38, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrayReferenceWithoutTypeArgs.ts" }
TypeScript/tests/cases/compiler/jsxClassAttributeResolution.tsx_0_609
// @jsx: react-jsx // @module: nodenext // @filename: file.tsx class App {} export const a = <App></App>; // @filename: node_modules/@types/react/package.json { "name": "@types/react", "version": "0.0.1", "main": "", "types": "index.d.ts", } // @filename: node_modules/@types/react/index.d.ts interface IntrinsicClassAttributesAlias<T> { ref: T } declare namespace JSX { type IntrinsicClassAttributes<T> = IntrinsicClassAttributesAlias<T> } // @filename: node_modules/@types/react/jsx-runtime.d.ts import './'; // @filename: node_modules/@types/react/jsx-dev-runtime.d.ts import './';
{ "end_byte": 609, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxClassAttributeResolution.tsx" }
TypeScript/tests/cases/compiler/optionalPropertiesSyntax.ts_0_674
interface fnSigs { //functions signatures can be optional fn(): void; fn?(): void; //err fn2?(): void; } interface callSig { //Call signatures can't be optional (): any; ()?: any; //err ?(): any; //err } interface constructSig { //Construct signatures can't be optional new (): any; new ()?: any; //err new ?(): any; //err } interface propertySig { //Property signatures can be optional prop: any; prop?: any; prop2?: any; } interface indexSig { //Index signatures can't be optional [idx: number]: any; [idx: number]?: any; //err ? [idx: number]: any; //err [idx?: number]: any; //err }
{ "end_byte": 674, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/optionalPropertiesSyntax.ts" }
TypeScript/tests/cases/compiler/bases.ts_0_190
interface I { x; } class B { constructor() { this.y: any; } } class C extends B implements I { constructor() { this.x: any; } } new C().x; new C().y;
{ "end_byte": 190, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/bases.ts" }
TypeScript/tests/cases/compiler/classExpressionAssignment.ts_0_83
interface A { prop: string; } // This is invalid const A: {new(): A} = class {}
{ "end_byte": 83, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/classExpressionAssignment.ts" }
TypeScript/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapesES6.ts_0_83
//@target: es6 function f(...args: any[]) { } f `\x0D${ "Interrupted CRLF" }\x0A`;
{ "end_byte": 83, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/taggedTemplateStringsHexadecimalEscapesES6.ts" }
TypeScript/tests/cases/compiler/unusedImports3.ts_0_270
//@noUnusedLocals:true //@noUnusedParameters:true // @Filename: file1.ts export class Calculator { handleChar() {} } export function test() { } export function test2() { } // @Filename: file2.ts import {Calculator, test, test2} from "./file1" test(); test2();
{ "end_byte": 270, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedImports3.ts" }
TypeScript/tests/cases/compiler/continueTarget1.ts_0_26
target: continue target;
{ "end_byte": 26, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/continueTarget1.ts" }
TypeScript/tests/cases/compiler/es5ExportDefaultExpression.ts_0_84
// @target: es5 // @module: commonjs // @declaration: true export default (1 + 2);
{ "end_byte": 84, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es5ExportDefaultExpression.ts" }
TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.ts_0_2850
// @lib: es5 // @sourcemap: true declare var console: { log(msg: any): void; } type Robot = [number, string, string]; type MultiSkilledRobot = [string, [string, string]]; let robotA: Robot = [1, "mower", "mowing"]; let robotB: Robot = [2, "trimmer", "trimming"]; let robots = [robotA, robotB]; function getRobots() { return robots; } let multiRobotA: MultiSkilledRobot = ["mower", ["mowing", ""]]; let multiRobotB: MultiSkilledRobot = ["trimmer", ["trimming", "edging"]]; let multiRobots = [multiRobotA, multiRobotB]; function getMultiRobots() { return multiRobots; } for (let [, nameA = "noName"] of robots) { console.log(nameA); } for (let [, nameA = "noName"] of getRobots()) { console.log(nameA); } for (let [, nameA = "noName"] of [robotA, robotB]) { console.log(nameA); } for (let [, [ primarySkillA = "primary", secondarySkillA = "secondary" ] = ["skill1", "skill2"]] of multiRobots) { console.log(primarySkillA); } for (let [, [ primarySkillA = "primary", secondarySkillA = "secondary" ] = ["skill1", "skill2"]] of getMultiRobots()) { console.log(primarySkillA); } for (let [, [ primarySkillA = "primary", secondarySkillA = "secondary" ] = ["skill1", "skill2"]] of [multiRobotA, multiRobotB]) { console.log(primarySkillA); } for (let [numberB = -1] of robots) { console.log(numberB); } for (let [numberB = -1] of getRobots()) { console.log(numberB); } for (let [numberB = -1] of [robotA, robotB]) { console.log(numberB); } for (let [nameB = "noName"] of multiRobots) { console.log(nameB); } for (let [nameB = "noName"] of getMultiRobots()) { console.log(nameB); } for (let [nameB = "noName"] of [multiRobotA, multiRobotB]) { console.log(nameB); } for (let [numberA2 = -1, nameA2 = "noName", skillA2 = "skill"] of robots) { console.log(nameA2); } for (let [numberA2 = -1, nameA2 = "noName", skillA2 = "skill"] of getRobots()) { console.log(nameA2); } for (let [numberA2 = -1, nameA2 = "noName", skillA2 = "skill"] of [robotA, robotB]) { console.log(nameA2); } for (let [nameMA = "noName", [ primarySkillA = "primary", secondarySkillA = "secondary" ] = ["skill1", "skill2"]] of multiRobots) { console.log(nameMA); } for (let [nameMA = "noName", [ primarySkillA = "primary", secondarySkillA = "secondary" ] = ["skill1", "skill2"]] of getMultiRobots()) { console.log(nameMA); } for (let [nameMA = "noName", [ primarySkillA = "primary", secondarySkillA = "secondary" ] = ["skill1", "skill2"]] of [multiRobotA, multiRobotB]) { console.log(nameMA); } for (let [numberA3 = -1, ...robotAInfo] of robots) { console.log(numberA3); } for (let [numberA3 = -1, ...robotAInfo] of getRobots()) { console.log(numberA3); } for (let [numberA3 = -1, ...robotAInfo] of [robotA, robotB]) { console.log(numberA3); }
{ "end_byte": 2850, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.ts" }
TypeScript/tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions1.ts_3_142
@target: es6 function f(x: TemplateStringsArray, y: string, z: string) { } // Incomplete call, not enough parameters. f `123qdawdrqw${
{ "end_byte": 142, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/taggedTemplatesWithIncompleteTemplateExpressions1.ts" }
TypeScript/tests/cases/compiler/superCallInStaticMethod.ts_0_949
class Doing { public static staticMethod() { } } class Other extends Doing { // in static method public static staticMethod() { super.staticMethod(); } // in a lambda inside a static method public static lambdaInsideAStaticMethod() { () => { super.staticMethod(); } } // in an object literal inside a static method public static objectLiteralInsideAStaticMethod() { return { a: () => { super.staticMethod(); }, b: super.staticMethod() }; } // in a getter public static get staticGetter() { super.staticMethod(); return 0; } // in a setter public static set staticGetter(value: number) { super.staticMethod(); } // in static method public static initializerInAStaticMethod(a = super.staticMethod()) { super.staticMethod(); } }
{ "end_byte": 949, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/superCallInStaticMethod.ts" }
TypeScript/tests/cases/compiler/exportsInAmbientModules1.ts_0_143
// @module: amd // @filename: external.d.ts export var x: number // @filename: main.ts declare module "M" { export {x} from "external" }
{ "end_byte": 143, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportsInAmbientModules1.ts" }
TypeScript/tests/cases/compiler/tslibReExportHelpers.ts_0_635
// @module: nodenext // @experimentalDecorators: true // @importHelpers: true // @Filename: /node_modules/tslib/index.d.ts export declare function __decorate(...args: any[]): any; // @Filename: /node_modules/tslib/index.d.mts export * 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 declare var decorator: any; @decorator export class Foo {}
{ "end_byte": 635, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/tslibReExportHelpers.ts" }
TypeScript/tests/cases/compiler/discriminatingUnionWithUnionPropertyAgainstUndefinedWithoutStrictNullChecks.ts_0_609
// @noEmit: true // strictNullChecks: false // repro #49643 interface A {} interface B {} declare let opts: | { objectRef?: undefined; getObjectRef: () => any } | { objectRef: A | B; getObjectRef?: undefined }; opts.objectRef || opts.getObjectRef(); // repro #49643 issuecomment-1174455723 interface X { foo: string; } interface Y { baz: number; } interface A2 { result: unknown; error: undefined; } interface B2 { error: X | Y; } const testMethod = (m: A2 | B2) => { if (m.error) { m; // should be A2 | B2 } else { m; // should be A2 | B2 } }
{ "end_byte": 609, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/discriminatingUnionWithUnionPropertyAgainstUndefinedWithoutStrictNullChecks.ts" }
TypeScript/tests/cases/compiler/amdDependencyCommentName3.ts_0_163
//@module: amd ///<amd-dependency path='bar' name='b'/> ///<amd-dependency path='foo'/> ///<amd-dependency path='goo' name='c'/> import m1 = require("m2") m1.f();
{ "end_byte": 163, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/amdDependencyCommentName3.ts" }
TypeScript/tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts_0_472
interface I { x1(a: number, callback: (x: 'hi') => number); } class C { x1(a: number, callback: (x: 'hi') => number); x1(a: number, callback: (x: string) => number) { callback('hi'); callback('bye'); var hm = "hm"; callback(hm); callback(1); // error } } var c: C; c.x1(1, (x: 'hi') => { return 1; } ); c.x1(1, (x: 'bye') => { return 1; } ); c.x1(1, (x) => { return 1; } ); c.x1(1, (x: number) => { return 1; } );
{ "end_byte": 472, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts" }
TypeScript/tests/cases/compiler/esNextWeakRefs_IterableWeakMap.ts_0_2853
// @lib: ESNext // @target: ESNext // @useDefineForClassFields: true // @strictNullChecks: true /** `static #cleanup` */ const IterableWeakMap_cleanup = ({ ref, set }: { readonly ref: WeakRef<object>; readonly set: Set<WeakRef<object>>; }) => { set.delete(ref); }; // Based on: https://github.com/tc39/proposal-weakrefs/blob/master/README.md#iterable-weakmaps export class IterableWeakMap<K extends object, V> implements WeakMap<K, V> { declare readonly [Symbol.toStringTag]: "IterableWeakMap"; #weakMap = new WeakMap<K, { readonly ref: WeakRef<K>; value: V }>(); #refSet = new Set<WeakRef<K>>(); #finalizationGroup = new FinalizationRegistry(IterableWeakMap_cleanup); constructor(iterable: Iterable<[key: K, value: V]> | null = null) { if (iterable !== null) { for (const { 0: key, 1: value } of iterable) { this.set(key, value); } } } set(key: K, value: V): this { const entry = this.#weakMap.get(key); if (entry !== undefined) { entry.value = value; } else { const ref = new WeakRef(key); this.#weakMap.set(key, { ref, value }); this.#refSet.add(ref); this.#finalizationGroup.register(key, { set: this.#refSet, ref, }, ref); } return this; } has(key: K): boolean { return this.#weakMap.has(key); } get(key: K): V | undefined { return this.#weakMap.get(key)?.value; } delete(key: K): boolean { const entry = this.#weakMap.get(key); if (entry === undefined) { return false; } const { ref } = entry; this.#weakMap.delete(key); this.#refSet.delete(ref); this.#finalizationGroup.unregister(ref); return true; } declare [Symbol.iterator]: this["entries"]; *entries(): Generator<[key: K, value: V], void> { for (const ref of this.#refSet) { const key = ref.deref(); if (key === undefined) continue; const { value } = this.#weakMap.get(key)!; yield [key, value]; } } *keys() { for (const { 0: key } of this) { yield key; } } *values() { for (const { 1: value } of this) { yield value; } } } Object.defineProperties(IterableWeakMap.prototype, { [Symbol.iterator]: { configurable: true, enumerable: false, writable: true, value: Object.getOwnPropertyDescriptor( IterableWeakMap.prototype, "entries", )!.value, }, [Symbol.toStringTag]: { configurable: true, enumerable: false, writable: false, value: "IterableWeakMap", }, });
{ "end_byte": 2853, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/esNextWeakRefs_IterableWeakMap.ts" }
TypeScript/tests/cases/compiler/systemModule2.ts_0_42
// @module: system var x = 1; export = x;
{ "end_byte": 42, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/systemModule2.ts" }
TypeScript/tests/cases/compiler/downlevelLetConst14.ts_0_724
// @target:es5 'use strict' declare function use(a: any); var x = 10; var z0, z1, z2, z3; { let x = 20; use(x); let [z0] = [1]; use(z0); let [z1] = [1] use(z1); let {a: z2} = { a: 1 }; use(z2); let {a: z3} = { a: 1 }; use(z3); } use(x); use(z0); use(z1); use(z2); use(z3); var z6; var y = true; { let y = ""; let [z6] = [true] { let y = 1; let {a: z6} = {a: 1} use(y); use(z6); } use(y); use(z6); } use(y); use(z6); var z = false; var z5 = 1; { let z = ""; let [z5] = [5]; { let _z = 1; let {a: _z5} = { a: 1 }; // try to step on generated name use(_z); } use(z); } use(y);
{ "end_byte": 724, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/downlevelLetConst14.ts" }
TypeScript/tests/cases/compiler/nestedBlockScopedBindings12.ts_0_112
var x; { let x; x = 1; } var y; switch (1) { case 1: let y; y = 1; break; }
{ "end_byte": 112, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nestedBlockScopedBindings12.ts" }
TypeScript/tests/cases/compiler/indexSignatureTypeCheck2.ts_0_248
class IPropertySet { [index: string]: any } var ps: IPropertySet = null; var index: any = "hello"; ps[index] = 12; interface indexErrors { [p2?: string]; [...p3: any[]]; [p4: string, p5?: string]; [p6: string, ...p7: any[]]; }
{ "end_byte": 248, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/indexSignatureTypeCheck2.ts" }
TypeScript/tests/cases/compiler/declarationEmitBundlerConditions.ts_0_633
// @module: esnext // @moduleResolution: bundler // @declaration: true // @emitDeclarationOnly: true // @noTypesAndSymbols: true // @Filename: /node_modules/pkg/package.json { "name": "pkg", "type": "module", "exports": { ".": { "import": "./index.js", "require": "./index.cjs" } } } // @Filename: /node_modules/pkg/index.d.ts export declare class C { private p; } // @Filename: /node_modules/pkg/index.d.cts export {}; // @Filename: /makeC.ts import { C } from "pkg"; export function makeC() { return new C(); } // @Filename: /index.ts import { makeC } from "./makeC"; export const c = makeC();
{ "end_byte": 633, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitBundlerConditions.ts" }
TypeScript/tests/cases/compiler/compareTypeParameterConstrainedByLiteralToLiteral.ts_0_136
// Test for #26758 function foo<T extends "a" | "b">(t: T) { t === "a"; // Should be allowed t === "x"; // Should be error }
{ "end_byte": 136, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/compareTypeParameterConstrainedByLiteralToLiteral.ts" }
TypeScript/tests/cases/compiler/classExpressionInClassStaticDeclarations.ts_0_68
// @declaration: true class C { static D = class extends C {}; }
{ "end_byte": 68, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/classExpressionInClassStaticDeclarations.ts" }
TypeScript/tests/cases/compiler/reachabilityChecks3.ts_0_173
// @allowUnusedLabels: false let x = 1; loop: while (true) { if (x == 100) { break; } else { x++; } } { x: 100 } var y = () => { f: 1 }
{ "end_byte": 173, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reachabilityChecks3.ts" }
TypeScript/tests/cases/compiler/nonInferrableTypePropagation1.ts_0_747
// @strict: true type Op<I, O> = (thing: Thing<I>) => Thing<O>; type Thing<T> = { value: T; pipe<A, B>( opA: Op<T, A>, opB: Op<A, B>, ): Thing<B>; }; type Box<V> = { data: V }; declare const thing: Thing<number>; declare function map<T, R>(project: (value: T) => R): Op<T, R>; declare function tap<T>(next: (value: T) => void): Op<T, T>; declare function box<V>(data: V): Box<V>; declare function createAndUnbox<V>(factory: () => Thing<V | Box<V>>): Thing<V>; declare function log(value: any): void; const result1 = createAndUnbox(() => thing.pipe( map((data) => box(data)), tap((v) => log(v)), )); const result2 = createAndUnbox(() => thing.pipe( tap((v) => log(v)), map((data) => box(data)), ));
{ "end_byte": 747, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nonInferrableTypePropagation1.ts" }
TypeScript/tests/cases/compiler/noEmitAndIncrementalListFilesOnly.ts_0_177
// @listFilesOnly: true // @Filename: /a.ts const x = 10; // @Filename: /tsconfig.json { "compilerOptions": { "noEmit": true, "incremental": true } }
{ "end_byte": 177, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/noEmitAndIncrementalListFilesOnly.ts" }
TypeScript/tests/cases/compiler/arrayBestCommonTypes.ts_3_4508
dule EmptyTypes { interface iface { } class base implements iface { } class base2 implements iface { } class derived extends base { } class f { public voidIfAny(x: boolean, y?: boolean): number; public voidIfAny(x: string, y?: boolean): number; public voidIfAny(x: number, y?: boolean): number; public voidIfAny(x: any, y = false): any { return null; } public x() { <number>(this.voidIfAny([4, 2][0])); <number>(this.voidIfAny([4, 2, undefined][0])); <number>(this.voidIfAny([undefined, 2, 4][0])); <number>(this.voidIfAny([null, 2, 4][0])); <number>(this.voidIfAny([2, 4, null][0])); <number>(this.voidIfAny([undefined, 4, null][0])); <number>(this.voidIfAny(['', "q"][0])); <number>(this.voidIfAny(['', "q", undefined][0])); <number>(this.voidIfAny([undefined, "q", ''][0])); <number>(this.voidIfAny([null, "q", ''][0])); <number>(this.voidIfAny(["q", '', null][0])); <number>(this.voidIfAny([undefined, '', null][0])); <number>(this.voidIfAny([[3, 4], [null]][0][0])); var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; var anyObj: any = null; // Order matters here so test all the variants var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; var ifaceObj: iface = null; var baseObj = new base(); var base2Obj = new base2(); var b1 = [baseObj, base2Obj, ifaceObj]; var b2 = [base2Obj, baseObj, ifaceObj]; var b3 = [baseObj, ifaceObj, base2Obj]; var b4 = [ifaceObj, baseObj, base2Obj]; } } } module NonEmptyTypes { interface iface { x: string; } class base implements iface { x: string; y: string; } class base2 implements iface { x: string; z: string; } class derived extends base { a: string; } class f { public voidIfAny(x: boolean, y?: boolean): number; public voidIfAny(x: string, y?: boolean): number; public voidIfAny(x: number, y?: boolean): number; public voidIfAny(x: any, y = false): any { return null; } public x() { <number>(this.voidIfAny([4, 2][0])); <number>(this.voidIfAny([4, 2, undefined][0])); <number>(this.voidIfAny([undefined, 2, 4][0])); <number>(this.voidIfAny([null, 2, 4][0])); <number>(this.voidIfAny([2, 4, null][0])); <number>(this.voidIfAny([undefined, 4, null][0])); <number>(this.voidIfAny(['', "q"][0])); <number>(this.voidIfAny(['', "q", undefined][0])); <number>(this.voidIfAny([undefined, "q", ''][0])); <number>(this.voidIfAny([null, "q", ''][0])); <number>(this.voidIfAny(["q", '', null][0])); <number>(this.voidIfAny([undefined, '', null][0])); <number>(this.voidIfAny([[3, 4], [null]][0][0])); var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; var anyObj: any = null; // Order matters here so test all the variants var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; var ifaceObj: iface = null; var baseObj = new base(); var base2Obj = new base2(); var b1 = [baseObj, base2Obj, ifaceObj]; var b2 = [base2Obj, baseObj, ifaceObj]; var b3 = [baseObj, ifaceObj, base2Obj]; var b4 = [ifaceObj, baseObj, base2Obj]; } } }
{ "end_byte": 4508, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrayBestCommonTypes.ts" }
TypeScript/tests/cases/compiler/declarationEmitRedundantTripleSlashModuleAugmentation.ts_0_553
// @declaration: true // @emitDeclarationOnly: true // @noTypesAndSymbols: true // @module: nodenext // @Filename: /node_modules/foo/index.d.ts declare module "foo" { export interface Original {} } // @Filename: /augmentation.ts export interface FooOptions {} declare module "foo" { export interface Augmentation {} } // @Filename: /index.ts import { Original, Augmentation } from "foo"; import type { FooOptions } from "./augmentation"; export interface _ { original: Original; augmentation: Augmentation; options: FooOptions; }
{ "end_byte": 553, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitRedundantTripleSlashModuleAugmentation.ts" }
TypeScript/tests/cases/compiler/augmentedTypesClass2.ts_0_369
// Checking class with other things in type space not value space // class then interface class c11 { foo() { return 1; } } interface c11 { bar(): void; } // class then class - covered // class then enum class c33 { foo() { return 1; } } enum c33 { One }; // class then import class c44 { foo() { return 1; } }
{ "end_byte": 369, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/augmentedTypesClass2.ts" }
TypeScript/tests/cases/compiler/subclassThisTypeAssignable01.ts_0_797
// @allowJs: true // @checkJs: true // @outDir: ./out // @filename: tile1.ts interface Lifecycle<Attrs, State> { oninit?(vnode: Vnode<Attrs, State>): number; [_: number]: any; } interface Vnode<Attrs, State extends Lifecycle<Attrs, State> = Lifecycle<Attrs, State>> { tag: Component<Attrs, State>; } interface Component<Attrs, State> { view(this: State, vnode: Vnode<Attrs, State>): number; } interface ClassComponent<A> extends Lifecycle<A, ClassComponent<A>> { oninit?(vnode: Vnode<A, this>): number; view(vnode: Vnode<A, this>): number; } interface MyAttrs { id: number } class C implements ClassComponent<MyAttrs> { view(v: Vnode<MyAttrs>) { return 0; } } const test8: ClassComponent<any> = new C(); // @filename: file1.js /** @type {ClassComponent<any>} */ const test9 = new C();
{ "end_byte": 797, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/subclassThisTypeAssignable01.ts" }
TypeScript/tests/cases/compiler/exportDefaultTypeAndFunctionOverloads.ts_0_221
export default function foo(value: number): number export default function foo(value: string): string export default function foo(value: string | number): string | number { return 1 } type Foo = {} export default Foo
{ "end_byte": 221, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportDefaultTypeAndFunctionOverloads.ts" }
TypeScript/tests/cases/compiler/duplicatePackage_packageIdIncludesSubModule.ts_0_391
// @noImplicitReferences: true // @Filename: /node_modules/foo/Foo.d.ts export default class Foo { protected source: boolean; } // @Filename: /node_modules/foo/Bar.d.ts // This is *not* the same! export const x: number; // @Filename: /node_modules/foo/package.json { "name": "foo", "version": "1.2.3" } // @Filename: /index.ts import Foo from "foo/Foo"; import { x } from "foo/Bar";
{ "end_byte": 391, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/duplicatePackage_packageIdIncludesSubModule.ts" }
TypeScript/tests/cases/compiler/duplicateVariablesByScope.ts_0_459
// @allowUnreachableCode: true // duplicate local variables are only reported at global scope module M { for (var j = 0; j < 10; j++) { } for (var j = 0; j < 10; j++) { } } function foo() { var x = 2; var x = 1; if (true) { var result = 1; } else { var result = 2; } } class C { foo() { try { var x = 1; } catch (e) { var x = 2; } } }
{ "end_byte": 459, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/duplicateVariablesByScope.ts" }
TypeScript/tests/cases/compiler/importsInAmbientModules3.ts_0_153
// @module: amd // @filename: external.d.ts export default class C {} // @filename: main.ts declare module "M" { import C = require("external"); }
{ "end_byte": 153, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/importsInAmbientModules3.ts" }
TypeScript/tests/cases/compiler/es6ImportDefaultBinding.ts_0_370
// @target: es6 // @declaration: true // @declaration: true // @filename: es6ImportDefaultBinding_0.ts var a = 10; export default a; // @filename: es6ImportDefaultBinding_1.ts import defaultBinding from "es6ImportDefaultBinding_0"; var x = defaultBinding; import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used
{ "end_byte": 370, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es6ImportDefaultBinding.ts" }
TypeScript/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts_0_95
// @target: ES6 // @Filename: file1.ts const var1 = 0; // @Filename: file2.ts const var1 = 0;
{ "end_byte": 95, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/letDeclarations-scopes-duplicates5.ts" }
TypeScript/tests/cases/compiler/returnTypeParameterWithModules.ts_0_382
module M1 { export function reduce<A>(ar, f, e?): Array<A> { return Array.prototype.reduce.apply(ar, e ? [f, e] : [f]); }; }; module M2 { import A = M1 export function compose() { A.reduce(arguments, compose2); }; export function compose2<B, C, D>(g: (x: B) => C, f: (x: D) => B): (x: D) => C { return function (x) { return g(f(x)); } }; };
{ "end_byte": 382, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/returnTypeParameterWithModules.ts" }
TypeScript/tests/cases/compiler/jsElementAccessNoContextualTypeCrash.ts_0_276
// @checkJs: true // @allowJs: true // @noEmit: true // @filename: jsElementAccessNoContextualTypeCrash.js var Common = {}; self['Common'] = self['Common'] || {}; /** * @param {string} string * @return {string} */ Common.localize = function (string) { return string; };
{ "end_byte": 276, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsElementAccessNoContextualTypeCrash.ts" }
TypeScript/tests/cases/compiler/nameCollisions.ts_0_627
module T { var x = 2; module x { // error export class Bar { test: number; } } module z { var t; } var z; // error module y { var b; } class y { } // error var w; module w { } //ok var f; function f() { } //error function f2() { } var f2; // error var i; interface i { } //ok class C { } function C() { } // error function C2() { } class C2 { } // error function fi() { } interface fi { } // ok class cli { } interface cli { } interface cli2 { } class cli2 { } }
{ "end_byte": 627, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nameCollisions.ts" }
TypeScript/tests/cases/compiler/indexer3.ts_0_113
var dateMap: { [x: string]: Date; } = {} var r: Date = dateMap["hello"] // result type includes indexer using BCT
{ "end_byte": 113, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/indexer3.ts" }
TypeScript/tests/cases/compiler/unclosedExportClause01.ts_0_247
// @module: commonjs // @filename: t1.ts export var x = "x"; // @filename: t2.ts export { x, from "./t1" // @filename: t3.ts export { from "./t1" // @filename: t4.ts export { x as a from "./t1" // @filename: t5.ts export { x as a, from "./t1"
{ "end_byte": 247, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unclosedExportClause01.ts" }
TypeScript/tests/cases/compiler/ambientEnumElementInitializer2.ts_0_38
declare enum E { e = -3 // Negative }
{ "end_byte": 38, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ambientEnumElementInitializer2.ts" }
TypeScript/tests/cases/compiler/moduleAssignmentCompat4.ts_0_172
module A { export module M { class C { } } } module B { export module M { export class D { } } } var a: A; var b: B; a = b; b = a; // error
{ "end_byte": 172, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleAssignmentCompat4.ts" }
TypeScript/tests/cases/compiler/outModuleConcatUmd.ts_0_234
// @target: ES5 // @sourcemap: true // @declaration: true // @module: umd // @outFile: all.js // This should error // @Filename: ref/a.ts export class A { } // @Filename: b.ts import {A} from "./ref/a"; export class B extends A { }
{ "end_byte": 234, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/outModuleConcatUmd.ts" }