_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
TypeScript/tests/cases/compiler/topFunctionTypeNotCallable.ts_0_116
// @strict: true // @noEmit: true // repro from #48840 declare let foo: (...args: never) => void; foo(); // error
{ "end_byte": 116, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/topFunctionTypeNotCallable.ts" }
TypeScript/tests/cases/compiler/optionalAccessorsInInterface1.ts_0_487
interface MyPropertyDescriptor { get? (): any; set? (v: any): void; } declare function defineMyProperty(o: any, p: string, attributes: MyPropertyDescriptor): any; defineMyProperty({}, "name", { get: function () { return 5; } }); interface MyPropertyDescriptor2 { get?: () => any; set?: (v: any) => void; } declare function defineMyProperty2(o: any, p: string, attributes: MyPropertyDescriptor2): any; defineMyProperty2({}, "name", { get: function () { return 5; } });
{ "end_byte": 487, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/optionalAccessorsInInterface1.ts" }
TypeScript/tests/cases/compiler/reExportGlobalDeclaration2.ts_0_239
// @module: commonjs // @filename: file1.d.ts declare interface I1 { x: number } declare interface I2 { x: number } // @filename: file2.ts export {I1, I1 as II1}; export {I2, I2 as II2}; export {I1 as III1}; export {I2 as III2};
{ "end_byte": 239, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reExportGlobalDeclaration2.ts" }
TypeScript/tests/cases/compiler/unusedVariablesinNamespaces2.ts_0_288
//@noUnusedLocals:true //@noUnusedParameters:true namespace Validation { const lettersRegexp = /^[A-Za-z]+$/; const numberRegexp = /^[0-9]+$/; export class LettersOnlyValidator { isAcceptable(s2: string) { return lettersRegexp.test(s2); } } }
{ "end_byte": 288, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedVariablesinNamespaces2.ts" }
TypeScript/tests/cases/compiler/declareDottedModuleName.ts_0_191
// @declaration: true module M { module P.Q { } // This shouldnt be emitted } module M { export module R.S { } //This should be emitted } module T.U { // This needs to be emitted }
{ "end_byte": 191, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declareDottedModuleName.ts" }
TypeScript/tests/cases/compiler/simpleRecursionWithBaseCase2.ts_0_889
// @strict: true // @noImplicitAny: true // @lib: esnext // @noEmit: true async function rec1() { if (Math.random() < 0.5) { return rec1(); } else { return "hello"; } } async function rec2() { if (Math.random() < 0.5) { return await rec2(); } else { return "hello"; } } async function rec3() { return rec3(); } async function rec4() { return await rec4(); } async function rec5() { if (Math.random() < 0.5) { return ((rec1())); } else { return "hello"; } } async function rec6() { if (Math.random() < 0.5) { return await ((rec1())); } else { return "hello"; } } declare const ps: Promise<string> | number; async function foo1() { if (Math.random() > 0.5) { return ps; } else { return await foo1(); } } async function foo2() { if (Math.random() > 0.5) { return ps; } else { return foo2(); } }
{ "end_byte": 889, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/simpleRecursionWithBaseCase2.ts" }
TypeScript/tests/cases/compiler/relativeNamesInClassicResolution.ts_0_105
// @module:amd // @filename: somefolder/a.ts import {x} from "./b" // @filename: b.ts export let x = 1;
{ "end_byte": 105, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/relativeNamesInClassicResolution.ts" }
TypeScript/tests/cases/compiler/typeofUndefined.ts_0_132
// @declaration: true var x: typeof undefined; var x: any; // shouldn't be an error since type is the same as the first declaration
{ "end_byte": 132, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeofUndefined.ts" }
TypeScript/tests/cases/compiler/topLevelBlockExpando.ts_0_1072
// https://github.com/microsoft/TypeScript/issues/31972 // @allowJs: true // @noEmit: true // @checkJs: true // @filename: check.ts // https://github.com/microsoft/TypeScript/issues/31972 interface Person { first: string; last: string; } { const dice = () => Math.floor(Math.random() * 6); dice.first = 'Rando'; dice.last = 'Calrissian'; const diceP: Person = dice; } // @filename: check.js // Creates a type { first:string, last: string } /** * @typedef {Object} Human - creates a new type named 'SpecialType' * @property {string} first - a string property of SpecialType * @property {string} last - a number property of SpecialType */ /** * @param {Human} param used as a validation tool */ function doHumanThings(param) {} const dice1 = () => Math.floor(Math.random() * 6); // dice1.first = 'Rando'; dice1.last = 'Calrissian'; // doHumanThings(dice) // but inside a block... you can't call a human { const dice2 = () => Math.floor(Math.random() * 6); dice2.first = 'Rando'; dice2.last = 'Calrissian'; doHumanThings(dice2) }
{ "end_byte": 1072, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/topLevelBlockExpando.ts" }
TypeScript/tests/cases/compiler/numberAssignableToEnumInsideUnion.ts_0_55
enum E { A, B } let n: number; let z: E | boolean = n;
{ "end_byte": 55, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/numberAssignableToEnumInsideUnion.ts" }
TypeScript/tests/cases/compiler/APISample_linter.ts_3_2880
@module: commonjs // @skipLibCheck: true // @noImplicitAny:true // @strictNullChecks:true // @noTypesAndSymbols: true // @filename: node_modules/typescript/package.json { "name": "typescript", "types": "/.ts/typescript.d.ts" } // @filename: APISample_linter.ts /* * Note: This test is a public API sample. The sample sources can be found * at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter * Please log a "breaking change" issue for any API breaking change affecting this issue */ declare var process: any; declare var console: any; declare var readFileSync: any; import * as ts from "typescript"; export function delint(sourceFile: ts.SourceFile) { delintNode(sourceFile); function delintNode(node: ts.Node) { switch (node.kind) { case ts.SyntaxKind.ForStatement: case ts.SyntaxKind.ForInStatement: case ts.SyntaxKind.WhileStatement: case ts.SyntaxKind.DoStatement: if ((<ts.IterationStatement>node).statement.kind !== ts.SyntaxKind.Block) { report(node, "A looping statement's contents should be wrapped in a block body."); } break; case ts.SyntaxKind.IfStatement: let ifStatement = (<ts.IfStatement>node); if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) { report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body."); } if (ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) { report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body."); } break; case ts.SyntaxKind.BinaryExpression: let op = (<ts.BinaryExpression>node).operatorToken.kind; if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) { report(node, "Use '===' and '!=='.") } break; } ts.forEachChild(node, delintNode); } function report(node: ts.Node, message: string) { let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart()); console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`); } } const fileNames: string[] = process.argv.slice(2); fileNames.forEach(fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES2015, /*setParentNodes */ true); // delint it delint(sourceFile); });
{ "end_byte": 2880, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/APISample_linter.ts" }
TypeScript/tests/cases/compiler/checkJsdocTypeTagOnExportAssignment2.ts_0_309
// @allowJs: true // @checkJs: true // @outDir: ./out // @filename: checkJsdocTypeTagOnExportAssignment2.js // @Filename: a.ts export interface Foo { a: number; b: number; } // @Filename: b.js /** @type {import("./a").Foo} */ export default { c: false }; // @Filename: c.js import b from "./b"; b;
{ "end_byte": 309, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkJsdocTypeTagOnExportAssignment2.ts" }
TypeScript/tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts_0_182
// @target: es5 // @experimentalDecorators: true // @emitDecoratorMetadata: true class A { @decorator public field1: -1 = -1; } function decorator(target: any, field: any) {}
{ "end_byte": 182, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts" }
TypeScript/tests/cases/compiler/unusedTypeParameterInMethod3.ts_0_153
//@noUnusedLocals:true //@noUnusedParameters:true class A { public f1<X, Y, Z>() { var a: X; var b: Y; a; b; } }
{ "end_byte": 153, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedTypeParameterInMethod3.ts" }
TypeScript/tests/cases/compiler/ClassDeclaration14.ts_0_39
class C { foo(); constructor(); }
{ "end_byte": 39, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ClassDeclaration14.ts" }
TypeScript/tests/cases/compiler/assignmentCompatability31.ts_0_338
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 aa:{one:string[];};; export var __val__aa = aa; } __test2__.__val__aa = __test1__.__val__obj4
{ "end_byte": 338, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/assignmentCompatability31.ts" }
TypeScript/tests/cases/compiler/mixinIntersectionIsValidbaseType.ts_0_725
export type Constructor<T extends object = object> = new (...args: any[]) => T; export interface Initable { init(...args: any[]): void; } /** * Plain mixin where the superclass must be Initable */ export const Serializable = <K extends Constructor<Initable> & Initable>( SuperClass: K ) => { const LocalMixin = (InnerSuperClass: K) => { return class SerializableLocal extends InnerSuperClass { } }; let ResultClass = LocalMixin(SuperClass); return ResultClass; }; const AMixin = <K extends Constructor<Initable> & Initable>(SuperClass: K) => { let SomeHowOkay = class A extends SuperClass { }; let SomeHowNotOkay = class A extends Serializable(SuperClass) { }; };
{ "end_byte": 725, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/mixinIntersectionIsValidbaseType.ts" }
TypeScript/tests/cases/compiler/duplicateIdentifierDifferentModifiers.ts_0_192
// Not OK interface B { x; } interface B { x?; } // OK class A { public y: string; } interface A { y: string; } // Not OK class C { private y: string; } interface C { y: string; }
{ "end_byte": 192, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/duplicateIdentifierDifferentModifiers.ts" }
TypeScript/tests/cases/compiler/syntheticDefaultExportsWithDynamicImports.ts_0_259
// @module: system // @target: es6 // @moduleResolution: node // @filename: node_modules/package/index.d.ts declare function packageExport(x: number): string; export = packageExport; // @filename: index.ts import("package").then(({default: foo}) => foo(42));
{ "end_byte": 259, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/syntheticDefaultExportsWithDynamicImports.ts" }
TypeScript/tests/cases/compiler/jsdocParamTagInvalid.ts_0_125
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /a.js /** @param {string} colour */ function f(color) {}
{ "end_byte": 125, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsdocParamTagInvalid.ts" }
TypeScript/tests/cases/compiler/typeParameterLeak.ts_0_403
// @strict: true // Repro from #35655 interface Box<T> { data: T } type BoxTypes = Box<{ x: string }> | Box<{ y: string }>; type BoxFactoryFactory<TBox> = TBox extends Box<infer T> ? { (arg: T): BoxFactory<TBox> | undefined } : never; interface BoxFactory<A> { getBox(): A, } declare const f: BoxFactoryFactory<BoxTypes>; const b = f({ x: "", y: "" })?.getBox(); if (b) { const x = b.data; }
{ "end_byte": 403, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeParameterLeak.ts" }
TypeScript/tests/cases/compiler/collisionExportsRequireAndEnum.ts_0_944
//@module: amd //@filename: collisionExportsRequireAndEnum_externalmodule.ts export enum require { // Error _thisVal1, _thisVal2, } export enum exports { // Error _thisVal1, _thisVal2, } module m1 { enum require { _thisVal1, _thisVal2, } enum exports { _thisVal1, _thisVal2, } } module m2 { export enum require { _thisVal1, _thisVal2, } export enum exports { _thisVal1, _thisVal2, } } //@filename: collisionExportsRequireAndEnum_globalFile.ts enum require { _thisVal1, _thisVal2, } enum exports { _thisVal1, _thisVal2, } module m3 { enum require { _thisVal1, _thisVal2, } enum exports { _thisVal1, _thisVal2, } } module m4 { export enum require { _thisVal1, _thisVal2, } export enum exports { _thisVal1, _thisVal2, } }
{ "end_byte": 944, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/collisionExportsRequireAndEnum.ts" }
TypeScript/tests/cases/compiler/narrowByParenthesizedSwitchExpression.ts_0_364
// @strict: true // @noEmit: true interface Base { type: "foo" | "bar"; } interface Foo extends Base { type: "foo"; foo: string; } interface Bar extends Base { type: "bar"; bar: number; } function getV(): Foo | Bar { return null!; } const v = getV(); switch ((v.type)) { case "bar": v.bar; break; case "foo": v.foo; break; }
{ "end_byte": 364, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/narrowByParenthesizedSwitchExpression.ts" }
TypeScript/tests/cases/compiler/arrayFakeFlatNoCrashInferenceDeclarations.ts_0_529
// @strict: true // @lib: es2020 // @declaration: true type BadFlatArray<Arr, Depth extends number> = {obj: { "done": Arr, "recur": Arr extends ReadonlyArray<infer InnerArr> ? BadFlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]> : Arr }[Depth extends -1 ? "done" : "recur"]}["obj"]; declare function flat<A, D extends number = 1>( arr: A, depth?: D ): BadFlatArray<A, D>[] function foo<T>(arr: T[], depth: number) { return flat(arr, depth); }
{ "end_byte": 529, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrayFakeFlatNoCrashInferenceDeclarations.ts" }
TypeScript/tests/cases/compiler/emptyFile-declaration.ts_0_79
// @target: ES5 // @sourcemap: false // @declaration: true // @module: commonjs
{ "end_byte": 79, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/emptyFile-declaration.ts" }
TypeScript/tests/cases/compiler/sourceMapValidationImport.ts_0_159
//@module: commonjs // @sourcemap: true export module m { export class c { } } import a = m.c; export import b = m.c; var x = new a(); var y = new b();
{ "end_byte": 159, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/sourceMapValidationImport.ts" }
TypeScript/tests/cases/compiler/parameterPropertyInConstructor1.ts_0_86
declare module mod { class Customers { constructor(public names: string); } }
{ "end_byte": 86, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/parameterPropertyInConstructor1.ts" }
TypeScript/tests/cases/compiler/ambientEnumElementInitializer6.ts_0_53
declare module M { enum E { e = 3 } }
{ "end_byte": 53, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ambientEnumElementInitializer6.ts" }
TypeScript/tests/cases/compiler/moduleAugmentationInAmbientModule3.ts_0_633
// @module: commonjs // @declaration: true; // @filename: O.d.ts declare module "Observable" { class Observable {} } declare module "M" { class Cls { x: number } } declare module "Map" { import { Cls } from "M"; module "Observable" { interface Observable { foo(): Cls; } } } declare module "Map" { class Cls2 { x2: number } module "Observable" { interface Observable { foo2(): Cls2; } } } // @filename: main.ts /// <reference path="O.d.ts" /> import {Observable} from "Observable"; import "Map"; let x: Observable; x.foo().x; x.foo2().x2;
{ "end_byte": 633, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleAugmentationInAmbientModule3.ts" }
TypeScript/tests/cases/compiler/pathMappingBasedModuleResolution_withExtensionInName.ts_0_430
// @traceResolution: true // @module: commonjs // @noImplicitReferences: true // @filename: /tsconfig.json { "compilerOptions": { "baseUrl": ".", "paths": { "*": ["foo/*"] } } } // @filename: /foo/zone.js/index.d.ts export const x: number; // @filename: /foo/zone.tsx/index.d.ts export const y: number; // @filename: /a.ts import { x } from "zone.js"; import { y } from "zone.tsx";
{ "end_byte": 430, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/pathMappingBasedModuleResolution_withExtensionInName.ts" }
TypeScript/tests/cases/compiler/internalAliasInitializedModuleInsideTopLevelModuleWithExport.ts_0_179
//@module: commonjs // @declaration: true export module a { export module b { export class c { } } } export import b = a.b; export var x: b.c = new b.c();
{ "end_byte": 179, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/internalAliasInitializedModuleInsideTopLevelModuleWithExport.ts" }
TypeScript/tests/cases/compiler/reachabilityChecks7.ts_0_539
// @target: ES6 // @noImplicitReturns: true // async function without return type annotation - error async function f1() { } let x = async function() { } // async function with which promised type is void - return can be omitted async function f2(): Promise<void> { } async function f3(x) { if (x) return 10; } async function f4(): Promise<number> { } function voidFunc(): void { } function calltoVoidFunc(x) { if (x) return voidFunc(); } declare function use(s: string): void; let x1 = () => { use("Test"); }
{ "end_byte": 539, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reachabilityChecks7.ts" }
TypeScript/tests/cases/compiler/defaultArgsInOverloads.ts_0_284
function fun(a: string); function fun(a = 3); function fun(a = null) { } class C { fun(a: string); fun(a = 3); fun(a = null) { } static fun(a: string); static fun(a = 3); static fun(a = null) { } } interface I { fun(a: string); fun(a = 3); } var f: (a = 3) => number;
{ "end_byte": 284, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/defaultArgsInOverloads.ts" }
TypeScript/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirDeclDirCompositeNestedDirs.ts_0_960
// @noImplicitReferences: true // @filename: tsconfig.json { "compilerOptions": { "module": "nodenext", "outDir": "./dist", "declarationDir": "./types", "composite": true } } // @filename: package.json { "name": "@this/package", "type": "module", "exports": { ".": { "default": "./dist/index.js", "types": "./types/index.d.ts" } } } // @filename: index.ts export {srcthing as thing} from "./src/thing.js"; // @filename: src/thing.ts // The following import should cause `index.ts` // to be included in the build, which will, // in turn, cause the common src directory to not be `src` // (the harness is wierd here in that noImplicitReferences makes only // this file get loaded as an entrypoint and emitted, while on the // real command-line we'll crawl the imports for that set - a limitation // of the harness, I suppose) import * as me from "@this/package"; me.thing(); export function srcthing(): void {}
{ "end_byte": 960, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nodeNextPackageSelfNameWithOutDirDeclDirCompositeNestedDirs.ts" }
TypeScript/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts_0_120
declare module X { export interface bar { } } declare module "m" { export { X }; export function foo(): X.bar; }
{ "end_byte": 120, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportSpecifierReferencingOuterDeclaration1.ts" }
TypeScript/tests/cases/compiler/commonSourceDir3.ts_0_139
// @useCaseSensitiveFileNames: false // @outDir: A:/ // @Filename: A:/foo/bar.ts var x: number; // @Filename: a:/foo/baz.ts var y: number;
{ "end_byte": 139, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/commonSourceDir3.ts" }
TypeScript/tests/cases/compiler/arrayFlatMap.ts_0_210
// @lib: es2019 const array: number[] = []; const readonlyArray: ReadonlyArray<number> = []; array.flatMap((): ReadonlyArray<number> => []); // ok readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
{ "end_byte": 210, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrayFlatMap.ts" }
TypeScript/tests/cases/compiler/extendedInterfaceGenericType.ts_0_236
interface Alpha<T> { takesArgOfT(arg: T): Alpha<T>; makeBetaOfNumber(): Beta<number>; } interface Beta<T> extends Alpha<T> { } var alpha: Alpha<number>; var betaOfNumber = alpha.makeBetaOfNumber(); betaOfNumber.takesArgOfT(5);
{ "end_byte": 236, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/extendedInterfaceGenericType.ts" }
TypeScript/tests/cases/compiler/mergedModuleDeclarationCodeGen3.ts_0_121
module my.data { export function buz() { } } module my.data.foo { function data(my, foo) { buz(); } }
{ "end_byte": 121, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/mergedModuleDeclarationCodeGen3.ts" }
TypeScript/tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts_4_273
var x = 10; switch (x) { case 1: case 2: default: // No issues. break; default: // Error; second 'default' clause. default: // Error; third 'default' clause. case 3: x *= x; }
{ "end_byte": 273, "start_byte": 4, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/switchStatementsWithMultipleDefaults1.ts" }
TypeScript/tests/cases/compiler/constructorParametersInVariableDeclarations.ts_0_244
class A { private a = x; private b = { p: x }; private c = () => x; constructor(x: number) { } } class B { private a = x; private b = { p: x }; private c = () => x; constructor() { var x = 1; } }
{ "end_byte": 244, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/constructorParametersInVariableDeclarations.ts" }
TypeScript/tests/cases/compiler/jsxPreserveWithJsInput.ts_0_267
// @outdir: out // @jsx: preserve // @allowjs: true // @filename: a.js var elemA = 42; // @filename: b.jsx var elemB = <b>{"test"}</b>; // @filename: c.js var elemC = <c>{42}</c>; // @filename: d.ts var elemD = 42; // @filename: e.tsx var elemE = <e>{true}</e>;
{ "end_byte": 267, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxPreserveWithJsInput.ts" }
TypeScript/tests/cases/compiler/importNonExportedMember7.ts_0_138
// @module: es2015 // @esModuleInterop: true // @Filename: a.ts class Foo {} export = Foo; // @Filename: b.ts import { Foo } from './a';
{ "end_byte": 138, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/importNonExportedMember7.ts" }
TypeScript/tests/cases/compiler/es5-asyncFunctionWithStatements.ts_0_476
// @lib: es5,es2015.promise // @noEmitHelpers: true // @target: ES5 declare var x, y, z, a, b, c; async function withStatement0() { with (x) { y; } } async function withStatement1() { with (await x) { y; } } async function withStatement2() { with (x) { a; await y; b; } } async function withStatement3() { with (x) { with (z) { a; await y; b; } } }
{ "end_byte": 476, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es5-asyncFunctionWithStatements.ts" }
TypeScript/tests/cases/compiler/varAsID.ts_1_151
class Foo { var; // ok x=1; } var f = new Foo(); class Foo2 { var // not an error, because of ASI. x=1; } var f2 = new Foo2();
{ "end_byte": 151, "start_byte": 1, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/varAsID.ts" }
TypeScript/tests/cases/compiler/recursiveInheritance3.ts_0_131
class C implements I { public foo(x: any) { return x; } private x = 1; } interface I extends C { other(x: any): any; }
{ "end_byte": 131, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/recursiveInheritance3.ts" }
TypeScript/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx_0_53
//@jsx: preserve declare var React: any; <foo data/>
{ "end_byte": 53, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx" }
TypeScript/tests/cases/compiler/genericFunctionInference2.ts_0_825
// Repro from #30685 type Reducer<S> = (state: S) => S; declare function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S>; type MyState = { combined: { foo: number } }; declare const foo: Reducer<MyState['combined']['foo']>; const myReducer1: Reducer<MyState> = combineReducers({ combined: combineReducers({ foo }), }); const myReducer2 = combineReducers({ combined: combineReducers({ foo }), }); // Repro from #30942 declare function withH<T, U>(handlerCreators: HandleCreatorsFactory<T, U>): U; type Props = { out: number } type HandleCreatorsFactory<T, U> = (initialProps: T) => { [P in keyof U]: (props: T) => U[P] }; const enhancer4 = withH((props: Props) => ({ onChange: (props) => (e: any) => {}, onSubmit: (props) => (e: any) => {}, })); enhancer4.onChange(null);
{ "end_byte": 825, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericFunctionInference2.ts" }
TypeScript/tests/cases/compiler/controlFlowNoImplicitAny.ts_0_2321
// @strictNullChecks: true // @noImplicitAny: true declare let cond: boolean; // CFA for 'let' with no type annotation and initializer function f1() { let x; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | undefined } // CFA for 'let' with no type annotation and 'undefined' initializer function f2() { let x = undefined; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | undefined } // CFA for 'let' with no type annotation and 'null' initializer function f3() { let x = null; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | null } // No CFA for 'let' with with type annotation function f4() { let x: any; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // any } // CFA for 'var' with no type annotation and initializer function f5() { var x; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | undefined } // CFA for 'var' with no type annotation and 'undefined' initializer function f6() { var x = undefined; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | undefined } // CFA for 'var' with no type annotation and 'null' initializer function f7() { var x = null; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | null } // No CFA for 'var' with with type annotation function f8() { var x: any; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // any } // No CFA for captured outer variables function f9() { let x; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | undefined function f() { const z = x; // any } } // No CFA for captured outer variables function f10() { let x; if (cond) { x = 1; } if (cond) { x = "hello"; } const y = x; // string | number | undefined const f = () => { const z = x; // any }; }
{ "end_byte": 2321, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/controlFlowNoImplicitAny.ts" }
TypeScript/tests/cases/compiler/accessors_spec_section-4.5_inference.ts_0_886
class A { } class B extends A { } class LanguageSpec_section_4_5_inference { public set InferredGetterFromSetterAnnotation(a: A) { } public get InferredGetterFromSetterAnnotation() { return new B(); } public get InferredGetterFromSetterAnnotation_GetterFirst() { return new B(); } public set InferredGetterFromSetterAnnotation_GetterFirst(a: A) { } public get InferredFromGetter() { return new B(); } public set InferredFromGetter(a) { } public set InferredFromGetter_SetterFirst(a) { } public get InferredFromGetter_SetterFirst() { return new B(); } public set InferredSetterFromGetterAnnotation(a) { } public get InferredSetterFromGetterAnnotation() : A { return new B(); } public get InferredSetterFromGetterAnnotation_GetterFirst() : A { return new B(); } public set InferredSetterFromGetterAnnotation_GetterFirst(a) { } }
{ "end_byte": 886, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/accessors_spec_section-4.5_inference.ts" }
TypeScript/tests/cases/compiler/narrowByClauseExpressionInSwitchTrue6.ts_0_1377
// @strict: true // @noEmit: true interface A { kind: "a"; aProps: string; } interface B { kind: "b"; bProps: string; } interface C { kind: "c"; cProps: string; } type MyType = A | B | C; function isA(x: MyType) { switch (true) { default: const never: never = x; case x.kind === "a": x.aProps; break; case x.kind === "b": x.bProps; break; case x.kind === "c": x.cProps; break; } switch (true) { default: const never: never = x; case x.kind === "a": { x.aProps; break; } case x.kind === "b": { x.bProps; break; } case x.kind === "c": { x.cProps; break; } } switch (true) { default: x.aProps; break; case x.kind === "b": x.bProps; break; case x.kind === "c": x.cProps; break; } switch (true) { default: const never: never = x; case x.kind === "a": x.aProps; // fallthrough case x.kind === "b": x.bProps; // fallthrough case x.kind === "c": x.cProps; } }
{ "end_byte": 1377, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/narrowByClauseExpressionInSwitchTrue6.ts" }
TypeScript/tests/cases/compiler/reexportMissingDefault6.ts_0_138
// @module: commonjs // @filename: b.ts export const b = null; // @filename: a.ts export { b } from "./b"; export { default } from "./b";
{ "end_byte": 138, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reexportMissingDefault6.ts" }
TypeScript/tests/cases/compiler/assignToFn.ts_0_126
module M { interface I { f(n:number):boolean; } var x:I={ f:function(n) { return true; } }; x.f="hello"; }
{ "end_byte": 126, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/assignToFn.ts" }
TypeScript/tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts_0_1256
// @strictNullChecks: true // @target: es2018 function f10(): undefined { // Ok, return type allows implicit return of undefined } function f11(): undefined | number { // Error, return type isn't just undefined } function f12(): number { // Error, return type doesn't include undefined } const f20: () => undefined = () => { // Ok, contextual type for implicit return is undefined } const f21: () => undefined | number = () => { // Error, regular void function because contextual type for implicit return isn't just undefined } const f22: () => number = () => { // Error, regular void function because contextual type for implicit return isn't just undefined } async function f30(): Promise<undefined> { // Ok, return type allows implicit return of undefined } async function f31(): Promise<undefined | number> { // Error, return type isn't just undefined } async function f32(): Promise<number> { // Error, return type doesn't include undefined } // Examples from #36288 declare function f(a: () => undefined): void; f(() => { }); f((): undefined => { }); const g1: () => undefined = () => { }; const g2 = (): undefined => { }; function h1() { } f(h1); // Error function h2(): undefined { } f(h2);
{ "end_byte": 1256, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionsMissingReturnStatementsAndExpressionsStrictNullChecks.ts" }
TypeScript/tests/cases/compiler/declFileIndexSignatures.ts_0_774
// @target: ES5 // @declaration: true // @removeComments: false // @module: commonjs // @Filename: declFileIndexSignatures_0.ts export interface IStringIndexSignature { [s: string]: string; } export interface INumberIndexSignature { [n: number]: number; } export interface IBothIndexSignature { [s: string]: any; [n: number]: number; } export interface IIndexSignatureWithTypeParameter<T> { [a: string]: T; } // @Filename: declFileIndexSignatures_1.ts interface IGlobalStringIndexSignature { [s: string]: string; } interface IGlobalNumberIndexSignature { [n: number]: number; } interface IGlobalBothIndexSignature { [s: string]: any; [n: number]: number; } interface IGlobalIndexSignatureWithTypeParameter<T> { [a: string]: T; }
{ "end_byte": 774, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declFileIndexSignatures.ts" }
TypeScript/tests/cases/compiler/objectRestBindingContextualInference.ts_0_564
// @strict: true // @noEmit: true // slimmed-down repro from #52629 type ImageHolder<K extends string> = { [P in K]: string; }; type SetupImageRefs<K extends string> = { [P in K]: File; }; type SetupImages<K extends string> = SetupImageRefs<K> & { prepare: () => { type: K }; }; interface TestInterface { name: string; image: string; } declare function setupImages<R extends ImageHolder<K>, K extends string>( item: R, keys: K[] ): SetupImages<K>; declare const test: TestInterface; const { prepare, ...rest } = setupImages(test, ["image"]);
{ "end_byte": 564, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/objectRestBindingContextualInference.ts" }
TypeScript/tests/cases/compiler/declarationEmitCommonJsModuleReferencedType.ts_0_793
// @declaration: true // @filename: r/node_modules/foo/node_modules/nested/index.d.ts export interface NestedProps {} // @filename: r/node_modules/foo/other/index.d.ts export interface OtherIndexProps {} // @filename: r/node_modules/foo/other.d.ts export interface OtherProps {} // @filename: r/node_modules/foo/index.d.ts import { OtherProps } from "./other"; import { OtherIndexProps } from "./other/index"; import { NestedProps } from "nested"; export interface SomeProps {} export function foo(): [SomeProps, OtherProps, OtherIndexProps, NestedProps]; // @filename: node_modules/root/index.d.ts export interface RootProps {} export function bar(): RootProps; // @filename: r/entry.ts import { foo } from "foo"; import { bar } from "root"; export const x = foo(); export const y = bar();
{ "end_byte": 793, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitCommonJsModuleReferencedType.ts" }
TypeScript/tests/cases/compiler/jsFileCompilationNonNullAssertion.ts_0_68
// @allowJs: true // @filename: /src/a.js // @outFile: /bin/a.js 0!
{ "end_byte": 68, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsFileCompilationNonNullAssertion.ts" }
TypeScript/tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts_0_1489
// @target: ES6 (function() { var s0; for ({ s0 = 5 } of [{ s0: 1 }]) { } }); (function() { var s0; for ({ s0:s0 = 5 } of [{ s0: 1 }]) { } }); (function() { var s1; for ({ s1 = 5 } of [{}]) { } }); (function() { var s1; for ({ s1:s1 = 5 } of [{}]) { } }); (function() { var s2; for ({ s2 = 5 } of [{ s2: "" }]) { } }); (function() { var s2; for ({ s2:s2 = 5 } of [{ s2: "" }]) { } }); (function() { var s3: string; for ({ s3 = 5 } of [{ s3: "" }]) { } }); (function() { var s3: string; for ({ s3:s3 = 5 } of [{ s3: "" }]) { } }); (function() { let y; ({ y = 5 } = { y: 1 }) }); (function() { let y; ({ y:y = 5 } = { y: 1 }) }); (function() { let y0: number; ({ y0 = 5 } = { y0: 1 }) }); (function() { let y0: number; ({ y0:y0 = 5 } = { y0: 1 }) }); (function() { let y1: string; ({ y1 = 5 } = {}) }); (function() { let y1: string; ({ y1:y1 = 5 } = {}) }); (function() { let y2: string, y3: { x: string }; ({ y2 = 5, y3 = { x: 1 } } = {}) }); (function() { let y2: string, y3: { x: string }; ({ y2:y2 = 5, y3:y3 = { x: 1 } } = {}) }); (function() { let y4: number, y5: { x: number }; ({ y4 = 5, y5 = { x: 1 } } = {}) }); (function() { let y4: number, y5: { x: number }; ({ y4:y4 = 5, y5:y5 = { x: 1 } } = {}) }); (function() { let z; ({ z = { x: 5 } } = { z: { x: 1 } }); }); (function() { let z; ({ z:z = { x: 5 } } = { z: { x: 1 } }); }); (function() { let a = { s = 5 }; }); function foo({a = 4, b = { x: 5 }}) { }
{ "end_byte": 1489, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts" }
TypeScript/tests/cases/compiler/genericConstructSignatureInInterface.ts_0_71
interface C { new <T>(x: T); } var v: C; var r = new v<number>(1);
{ "end_byte": 71, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericConstructSignatureInInterface.ts" }
TypeScript/tests/cases/compiler/moduleResolutionNoTsCJS.ts_0_411
// CommonJS output // @module: commonjs // @jsx: Preserve // @filename: x.ts export default 0; // @filename: y.tsx export default 0; // @filename: z.d.ts declare const x: number; export default x; // @filename: user.ts import x from "./x.ts"; import y from "./y.tsx"; import z from "./z.d.ts"; // Making sure the suggested fixes are valid: import x2 from "./x"; import y2 from "./y"; import z2 from "./z";
{ "end_byte": 411, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleResolutionNoTsCJS.ts" }
TypeScript/tests/cases/compiler/substitutionTypesCompareCorrectlyInRestrictiveInstances.ts_0_336
// @strict: true type UnionKeys<T> = T extends any ? keyof T : never; type BugHelper<T, TAll> = T extends any ? Exclude<UnionKeys<TAll>, keyof T> : never type Bug<TAll> = BugHelper<TAll, TAll> type Q = UnionKeys<{ a : any } | { b: any }> // should be "a" | "b" type R = Bug<{ a : any } | { b: any }> // should be "a" | "b"
{ "end_byte": 336, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/substitutionTypesCompareCorrectlyInRestrictiveInstances.ts" }
TypeScript/tests/cases/compiler/typeReferenceDirectives3.ts_0_436
// @noImplicitReferences: true // @declaration: true // @typeRoots: /types // @traceResolution: true // @currentDirectory: / // $ comes from d.ts file - no need to add type reference directive // @filename: /ref.d.ts interface $ { x } // @filename: /types/lib/index.d.ts declare let $: { x: number } // @filename: /app.ts /// <reference types="lib" preserve="true" /> /// <reference path="ref.d.ts" /> interface A { x: () => $ }
{ "end_byte": 436, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeReferenceDirectives3.ts" }
TypeScript/tests/cases/compiler/functionToFunctionWithPropError.ts_0_90
declare let x: { (): string; prop: number }; declare let y: { (): string; } x = y; y = x;
{ "end_byte": 90, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionToFunctionWithPropError.ts" }
TypeScript/tests/cases/compiler/conflictingTypeAnnotatedVar.ts_0_70
var foo: string; function foo(): number { } function foo(): number { }
{ "end_byte": 70, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/conflictingTypeAnnotatedVar.ts" }
TypeScript/tests/cases/compiler/constDeclarations-access5.ts_0_553
// @target: ES6 // @module: amd // @Filename: constDeclarations_access_1.ts export const x = 0; // @Filename: constDeclarations_access_2.ts ///<reference path='constDeclarations_access_1.ts'/> import m = require('constDeclarations_access_1'); // Errors m.x = 1; m.x += 2; m.x -= 3; m.x *= 4; m.x /= 5; m.x %= 6; m.x <<= 7; m.x >>= 8; m.x >>>= 9; m.x &= 10; m.x |= 11; m.x ^= 12; m m.x++; m.x--; ++m.x; --m.x; ++((m.x)); m["x"] = 0; // OK var a = m.x + 1; function f(v: number) { } f(m.x); if (m.x) { } m.x; (m.x); -m.x; +m.x; m.x.toString();
{ "end_byte": 553, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/constDeclarations-access5.ts" }
TypeScript/tests/cases/compiler/commonjsSafeImport.ts_0_172
// @target: ES5 // @module: commonjs // @declaration: true // @filename: 10_lib.ts export function Foo() {} // @filename: main.ts import { Foo } from './10_lib'; Foo();
{ "end_byte": 172, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/commonjsSafeImport.ts" }
TypeScript/tests/cases/compiler/unusedPrivateMembers.ts_0_880
//@noUnusedLocals:true //@noUnusedParameters:true //@target:ES5 class Test1 { private initializeInternal() { } public test() { var x = new Test1(); x.initializeInternal(); } } class Test2 { private p = 0; public test() { var x = new Test2(); x.p; } } class Test3 { private get x () { return 0; } public test() { var x = new Test3(); x.x; } } class Test4 { private set x(v) { v; } public test() { var x = new Test4(); x.x; } } class Test5<T> { private p: T; public test() { var x = new Test5<number>(); x.p; } } class Test6 { private get a() { return 0; } private set a(v) { v; } private b = 0; public test() { var x = new Test6(); x.a++; } }
{ "end_byte": 880, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedPrivateMembers.ts" }
TypeScript/tests/cases/compiler/generics0.ts_0_119
// @declaration: true interface G<T> { x: T; } var v2: G<string>; var z = v2.x; // 'y' should be of type 'string'
{ "end_byte": 119, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/generics0.ts" }
TypeScript/tests/cases/compiler/scopeCheckInsidePublicMethod1.ts_0_65
class C { static s; public a() { s = 1; // ERR } }
{ "end_byte": 65, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/scopeCheckInsidePublicMethod1.ts" }
TypeScript/tests/cases/compiler/exportStarForValues3.ts_0_391
// @module: amd // @filename: file1.ts export interface Foo { x } // @filename: file2.ts export interface A { x } export * from "file1" var x = 1; // @filename: file3.ts export interface B { x } export * from "file1" var x = 1; // @filename: file4.ts export interface C { x } export * from "file2" export * from "file3" var x = 1; // @filename: file5.ts export * from "file4" var x = 1;
{ "end_byte": 391, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportStarForValues3.ts" }
TypeScript/tests/cases/compiler/functionCall14.ts_0_111
function foo(a?:string, ...b:number[]){} foo('foo', 1); foo('foo'); foo(); foo(1, 'bar'); foo('foo', 1, 3);
{ "end_byte": 111, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionCall14.ts" }
TypeScript/tests/cases/compiler/interfaceImplementation3.ts_0_174
interface I1 { iObj:{ }; iNum:number; iAny:any; iFn():void; } class C4 implements I1 { public iObj:{ }; public iNum:number; public iFn() { } }
{ "end_byte": 174, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/interfaceImplementation3.ts" }
TypeScript/tests/cases/compiler/es5-commonjs3.ts_0_132
// @target: ES5 // @sourcemap: false // @declaration: false // @module: commonjs export default "test"; export var __esModule = 1;
{ "end_byte": 132, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es5-commonjs3.ts" }
TypeScript/tests/cases/compiler/out-flag.ts_0_310
// @target: ES5 // @sourcemap: true // @declaration: true // @module: commonjs //// @outFile: bin\ // @removeComments: false // my class comments class MyClass { // my function comments public Count(): number { return 42; } public SetCount(value: number) { // } }
{ "end_byte": 310, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/out-flag.ts" }
TypeScript/tests/cases/compiler/moduleAugmentationsImports2.ts_0_778
// @module: amd // @declaration: true // @outFile: f.js // @filename: a.ts export class A {} // @filename: b.ts export class B {x: number;} // @filename: c.d.ts declare module "C" { class Cls {y: string; } } // @filename: d.ts /// <reference path="c.d.ts"/> import {A} from "./a"; import {B} from "./b"; A.prototype.getB = function () { return undefined; } declare module "./a" { interface A { getB(): B; } } // @filename: e.ts import {A} from "./a"; import {Cls} from "C"; A.prototype.getCls = function () { return undefined; } declare module "./a" { interface A { getCls(): Cls; } } // @filename: main.ts import {A} from "./a"; import "d"; import "e"; let a: A; let b = a.getB().x.toFixed(); let c = a.getCls().y.toLowerCase();
{ "end_byte": 778, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleAugmentationsImports2.ts" }
TypeScript/tests/cases/compiler/asiContinue.ts_3_24
ile (true) continue
{ "end_byte": 24, "start_byte": 3, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/asiContinue.ts" }
TypeScript/tests/cases/compiler/withExportDecl.ts_0_1163
//@module: amd // @declaration: true var simpleVar; export var exportedSimpleVar; var anotherVar: any; var varWithSimpleType: number; var varWithArrayType: number[]; var varWithInitialValue = 30; export var exportedVarWithInitialValue = 70; var withComplicatedValue = { x: 30, y: 70, desc: "position" }; export var exportedWithComplicatedValue = { x: 30, y: 70, desc: "position" }; declare var declaredVar; declare var declareVar2 declare var declaredVar; declare var deckareVarWithType: number; export declare var exportedDeclaredVar: number; var arrayVar: string[] = ['a', 'b']; export var exportedArrayVar: { x: number; y: string; }[] ; exportedArrayVar.push({ x: 30, y : 'hello world' }); function simpleFunction() { return { x: "Hello", y: "word", n: 2 }; } export function exportedFunction() { return simpleFunction(); } module m1 { export function foo() { return "Hello"; } } export declare module m2 { export var a: number; } export module m3 { export function foo() { return m1.foo(); } } export var eVar1, eVar2 = 10; var eVar22; export var eVar3 = 10, eVar4, eVar5;
{ "end_byte": 1163, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/withExportDecl.ts" }
TypeScript/tests/cases/compiler/switchCaseInternalComments.ts_0_259
/*-1*/ foo /*0*/ : /*1*/ switch /*2*/ ( /*3*/ false /*4*/ ) /*5*/ { /*6*/ case /*7*/ false /*8*/ : /*9*/ /*10*/ break /*11*/ foo /*12*/; /*13*/ default /*14*/ : /*15*/ /*16*/ case /*17*/ false /*18*/ : /*19*/ { /*20*/ /*21*/ } /*22*/ }
{ "end_byte": 259, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/switchCaseInternalComments.ts" }
TypeScript/tests/cases/compiler/declarationEmitTripleSlashReferenceAmbientModule.ts_0_457
// @declaration: true // @emitDeclarationOnly: true // @noTypesAndSymbols: true // @Filename: /node_modules/@types/node/index.d.ts declare module "url" { export class Url {} export function parse(): Url; } // @Filename: /usage1.ts export { parse } from "url"; // @Filename: /usage2.ts import { parse } from "url"; export const thing: import("url").Url = parse(); // @Filename: /usage3.ts import { parse } from "url"; export const thing = parse();
{ "end_byte": 457, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitTripleSlashReferenceAmbientModule.ts" }
TypeScript/tests/cases/compiler/getAndSetAsMemberNames.ts_0_288
class C1 { set: boolean; get = 1; } class C2 { set; } class C3 { set (x) { return x + 1; } } class C4 { get: boolean = true; } class C5 { public set: () => boolean = function () { return true; }; get (): boolean { return true; } set t(x) { } }
{ "end_byte": 288, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/getAndSetAsMemberNames.ts" }
TypeScript/tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts_0_3744
// @strict: true export type FilterPropsByType<T, TT> = { [K in keyof T]: T[K] extends TT ? K : never }[keyof T]; function select< T extends string | number, TList extends object, TValueProp extends FilterPropsByType<TList, T> >(property: T, list: TList[], valueProp: TValueProp) {} export function func<XX extends string>(x: XX, tipos: { value: XX }[]) { select(x, tipos, "value"); } declare function onlyNullablePlease<T extends null extends T ? any : never>( value: T ): void; declare function onlyNullablePlease2< T extends [null] extends [T] ? any : never >(value: T): void; declare var z: string | null; onlyNullablePlease(z); // works as expected onlyNullablePlease2(z); // works as expected declare var y: string; onlyNullablePlease(y); // error as expected onlyNullablePlease2(y); // error as expected function f<T>(t: T) { var x: T | null = Math.random() > 0.5 ? null : t; onlyNullablePlease(x); // should work onlyNullablePlease2(x); // should work } function f2<T>(t1: { x: T; y: T }, t2: T extends T ? { x: T; y: T } : never) { t1 = t2; // OK t2 = t1; // should fail } type Foo<T> = T extends true ? string : "a"; function test<T>(x: Foo<T>, s: string) { x = "a"; // Currently an error, should be ok x = s; // Error } // #26933 type Distributive<T> = T extends { a: number } ? { a: number } : { b: number }; function testAssignabilityToConditionalType<T>() { const o = { a: 1, b: 2 }; const x: [T] extends [string] ? { y: number } : { a: number; b: number } = undefined!; // Simple case: OK const o1: [T] extends [number] ? { a: number } : { b: number } = o; // Simple case where source happens to be a conditional type: also OK const x1: [T] extends [number] ? ([T] extends [string] ? { y: number } : { a: number }) : ([T] extends [string] ? { y: number } : { b: number }) = x; // Infer type parameters: no good const o2: [T] extends [[infer U]] ? U : { b: number } = o; // The next 4 are arguable - if you choose to ignore the `never` distribution case, // then they're all good. The `never` case _is_ a bit of an outlier - we say distributive types // look approximately like the sum of their branches, but the `never` case bucks that. // There's an argument for the result of dumping `never` into a distributive conditional // being not `never`, but instead the intersection of the branches - a much more precise bound // on that "impossible" input. // Distributive where T might instantiate to never: no good const o3: Distributive<T> = o; // Distributive where T & string might instantiate to never: also no good const o4: Distributive<T & string> = o; // Distributive where {a: T} cannot instantiate to never: OK const o5: Distributive<{ a: T }> = o; // Distributive where check type is a conditional which returns a non-never type upon instantiation with `never` but can still return never otherwise: no good const o6: Distributive<[T] extends [never] ? { a: number } : never> = o; } type Wrapped<T> = { ___secret: T }; type Unwrap<T> = T extends Wrapped<infer U> ? U : T; declare function set<T, K extends keyof T>( obj: T, key: K, value: Unwrap<T[K]> ): Unwrap<T[K]>; class Foo2 { prop!: Wrapped<string>; method() { set(this, "prop", "hi"); // <-- type error } } set(new Foo2(), "prop", "hi"); // <-- typechecks type InferBecauseWhyNot<T> = [T] extends [(p: infer P1) => any] ? P1 | T : never; function f3<Q extends (arg: any) => any>(x: Q): InferBecauseWhyNot<Q> { return x; } type InferBecauseWhyNotDistributive<T> = T extends (p: infer P1) => any ? P1 | T : never; function f4<Q extends (arg: any) => any>( x: Q ): InferBecauseWhyNotDistributive<Q> { return x; // should fail }
{ "end_byte": 3744, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts" }
TypeScript/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx_0_673
// @jsx: react-jsx // @module: nodenext // @traceResolution: true // @filename: package.json { "type": "module" } // @filename: file.tsx export const a = <div></div>; // @filename: node_modules/@types/react/package.json { "name": "@types/react", "version": "0.0.1", "main": "", "types": "index.d.ts", "exports": { "./*.js": "./*.js", "./*": "./*.js" } } // @filename: node_modules/@types/react/index.d.ts declare namespace JSX { interface IntrinsicElements { [x: string]: any; } } // @filename: node_modules/@types/react/jsx-runtime.d.ts import './'; // @filename: node_modules/@types/react/jsx-dev-runtime.d.ts import './';
{ "end_byte": 673, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reactJsxReactResolvedNodeNextEsm.tsx" }
TypeScript/tests/cases/compiler/genericInstanceOf.ts_0_160
interface F { (): number; } class C<T> { constructor(public a: T, public b: F) {} foo() { if (this.a instanceof this.b) { } } }
{ "end_byte": 160, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericInstanceOf.ts" }
TypeScript/tests/cases/compiler/invalidUnicodeEscapeSequance4.ts_0_84
var a\u0031; // a1 is a valid identifier var \u0031a; // 1a is an invalid identifier
{ "end_byte": 84, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/invalidUnicodeEscapeSequance4.ts" }
TypeScript/tests/cases/compiler/intersectionOfTypeVariableHasApparentSignatures.ts_0_320
// @strictNullChecks: true // @noImplicitAny: true interface Component<P> { props: Readonly<P> & Readonly<{ children?: {} }>; } interface Props { children?: (items: {x: number}) => void } declare function f<T extends Props>(i: Component<T>): void; f({ props: { children: (({ x }) => { }) } });
{ "end_byte": 320, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/intersectionOfTypeVariableHasApparentSignatures.ts" }
TypeScript/tests/cases/compiler/commentsMultiModuleMultiFile.ts_0_715
// @module: amd // @target: ES5 // @declaration: true // @removeComments: false // @Filename: commentsMultiModuleMultiFile_0.ts /** this is multi declare module*/ export module multiM { /// class b comment export class b { } } /** thi is multi module 2*/ export module multiM { /** class c comment*/ export class c { } // class e comment export class e { } } new multiM.b(); new multiM.c(); // @Filename: commentsMultiModuleMultiFile_1.ts import m = require('commentsMultiModuleMultiFile_0'); /** this is multi module 3 comment*/ export module multiM { /** class d comment*/ export class d { } /// class f comment export class f { } } new multiM.d();
{ "end_byte": 715, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/commentsMultiModuleMultiFile.ts" }
TypeScript/tests/cases/compiler/jsxMultilineAttributeValuesReact.tsx_0_176
// @jsx: react declare var React: any; const a = <input value=" foo: 23 "></input>; const b = <input value=' foo: 23 '></input>; const c = <input value=' foo: 23\n '></input>;
{ "end_byte": 176, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxMultilineAttributeValuesReact.tsx" }
TypeScript/tests/cases/compiler/optionalPropertiesInClasses.ts_0_229
interface ifoo { x?:number; y:number; } class C1 implements ifoo { public y:number; } class C2 implements ifoo { // ERROR - still need 'y' public x:number; } class C3 implements ifoo { public x:number; public y:number; }
{ "end_byte": 229, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/optionalPropertiesInClasses.ts" }
TypeScript/tests/cases/compiler/deeplyNestedTemplateLiteralIntersection.ts_0_367
// @strict: true // @noEmit: true // @noTypesAndSymbols: true type R = `${number}a` & { _thing: true; }; type _S = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8"; type S = `${_S}${_S}`; type T = R | S; type X = `${T} ${T}`; export type Props = Partial<{ x: X; }>; const a1: Props = {}; const a2: Props = {}; const b = { ...a1, ...a2 }; export { b };
{ "end_byte": 367, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/deeplyNestedTemplateLiteralIntersection.ts" }
TypeScript/tests/cases/compiler/objectLiteralArraySpecialization.ts_0_352
declare function create<T>(initialValues?: T[]): MyArrayWrapper<T>; interface MyArrayWrapper<T> { constructor(initialItems?: T[]); doSomething(predicate: (x: T, y: T) => boolean): void; } var thing = create([ { name: "bob", id: 24 }, { name: "doug", id: 32 } ]); // should not error thing.doSomething((x, y) => x.name === "bob"); // should not error
{ "end_byte": 352, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/objectLiteralArraySpecialization.ts" }
TypeScript/tests/cases/compiler/thisInTupleTypeParameterConstraints.ts_0_592
/// <reference no-default-lib="true"/> interface Boolean {} interface IArguments {} interface Function {} interface Number {} interface RegExp {} interface Object {} interface String {} interface Array<T> { // 4 methods will run out of memory if this-types are not instantiated // correctly for tuple types that are type parameter constraints map<U>(arg: this): void; reduceRight<U>(arg: this): void; reduce<U>(arg: this): void; reduce2<U>(arg: this): void; } declare function f<T extends [(x: number) => number]>(a: T): void; let x: [(x: number) => number]; f(x);
{ "end_byte": 592, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/thisInTupleTypeParameterConstraints.ts" }
TypeScript/tests/cases/compiler/recursiveReturns.ts_0_137
function R1() { R1(); return; } function R2() { R2(); } function R3(n:number) { if (n == 0) { //return; } else { R3(n--); } }
{ "end_byte": 137, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/recursiveReturns.ts" }
TypeScript/tests/cases/compiler/typeInferenceLiteralUnion.ts_0_876
// Repro from #10901 /** * Administrivia: JavaScript primitive types and Date */ export type Primitive = number | string | boolean | Date; /** * Administrivia: anything with a valueOf(): number method is comparable, so we allow it in numeric operations */ interface Numeric { valueOf(): number; } // Not very useful, but meets Numeric class NumCoercible { public a: number; constructor(a: number) { this.a = a; } public valueOf() { return this.a; } } /** * Return the min and max simultaneously. */ export function extent<T extends Numeric>(array: Array<T | Primitive>): [T | Primitive, T | Primitive] | [undefined, undefined] { return [undefined, undefined]; } let extentMixed: [Primitive | NumCoercible, Primitive | NumCoercible] | [undefined, undefined]; extentMixed = extent([new NumCoercible(10), 13, '12', true]);
{ "end_byte": 876, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeInferenceLiteralUnion.ts" }
TypeScript/tests/cases/compiler/genericLambaArgWithoutTypeArguments.ts_0_104
interface Foo<T> { x: T; } function foo(a) { return null; } foo((arg: Foo) => { return arg.x; });
{ "end_byte": 104, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericLambaArgWithoutTypeArguments.ts" }
TypeScript/tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile.ts_0_3604
// @module: commonjs // @declaration: true // @Filename: privacyInterfaceExtendsClauseDeclFile_externalModule.ts export module publicModule { export interface publicInterfaceInPublicModule { } interface privateInterfaceInPublicModule { } interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { } interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { } export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { } export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error } interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { } export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error } export interface publicInterfaceImplementingPrivateAndPublicInterface extends privateInterfaceInPublicModule, publicInterfaceInPublicModule { // Should error } } module privateModule { export interface publicInterfaceInPrivateModule { } interface privateInterfaceInPrivateModule { } interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { } interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { } export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPrivateModule { } export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPrivateModule { } interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { } export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { } } export interface publicInterface { } interface privateInterface { } interface privateInterfaceImplementingPublicInterface extends publicInterface { } interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterface { } export interface publicInterfaceImplementingPublicInterface extends publicInterface { } export interface publicInterfaceImplementingPrivateInterface extends privateInterface { // Should error } interface privateInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { } export interface publicInterfaceImplementingFromPrivateModuleInterface extends privateModule.publicInterfaceInPrivateModule { // Should error } // @Filename: privacyInterfaceExtendsClauseDeclFile_GlobalFile.ts module publicModuleInGlobal { export interface publicInterfaceInPublicModule { } interface privateInterfaceInPublicModule { } interface privateInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { } interface privateInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { } export interface publicInterfaceImplementingPublicInterfaceInModule extends publicInterfaceInPublicModule { } export interface publicInterfaceImplementingPrivateInterfaceInModule extends privateInterfaceInPublicModule { // Should error } } interface publicInterfaceInGlobal { } interface publicInterfaceImplementingPublicInterfaceInGlobal extends publicInterfaceInGlobal { }
{ "end_byte": 3604, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/privacyInterfaceExtendsClauseDeclFile.ts" }
TypeScript/tests/cases/compiler/requireOfJsonFileWithoutEsModuleInterop.ts_0_272
// @module: commonjs // @moduleResolution: node // @target:es2017 // @strict: true // @resolveJsonModule: true // @outdir: out/ // @fullEmitPaths: true // @Filename: file1.ts import * as test from "./test.json" // @Filename: test.json { "a": true, "b": "hello" }
{ "end_byte": 272, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/requireOfJsonFileWithoutEsModuleInterop.ts" }
TypeScript/tests/cases/compiler/anyIdenticalToItself.ts_0_181
function foo(x: any); function foo(x: any); function foo(x: any, y: number) { } class C { get X(): any { var y: any; return y; } set X(v: any) { } }
{ "end_byte": 181, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/anyIdenticalToItself.ts" }
TypeScript/tests/cases/compiler/es6ImportNamedImportParsingError.ts_0_413
// @target: es6 // @filename: es6ImportNamedImportParsingError_0.ts export var a = 10; export var x = a; export var m = a; // @filename: es6ImportNamedImportParsingError_1.ts import { * } from "es6ImportNamedImportParsingError_0"; import defaultBinding, from "es6ImportNamedImportParsingError_0"; import , { a } from "es6ImportNamedImportParsingError_0"; import { a }, from "es6ImportNamedImportParsingError_0";
{ "end_byte": 413, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es6ImportNamedImportParsingError.ts" }
TypeScript/tests/cases/compiler/implicitAnyDeclareFunctionExprWithoutFormalType.ts_0_610
// @noimplicitany: true // these should be errors for implicit any parameter var lambda = (l1) => { }; // Error at "l1" var lambd2 = (ll1, ll2: string) => { } // Error at "ll1" var lamda3 = function myLambda3(myParam) { } var lamda4 = () => { return null }; // these should be error for implicit any return type var lambda5 = function temp() { return null; } var lambda6 = () => { return null; } var lambda7 = function temp() { return undefined; } var lambda8 = () => { return undefined; } // this shouldn't be an error var lambda9 = () => { return 5; } var lambda10 = function temp1() { return 5; }
{ "end_byte": 610, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/implicitAnyDeclareFunctionExprWithoutFormalType.ts" }