_id stringlengths 21 254 | text stringlengths 1 93.7k | metadata dict |
|---|---|---|
TypeScript/tests/cases/compiler/es5-yieldFunctionObjectLiterals.ts_0_927 | // @lib: es5,es2015.promise
// @noEmitHelpers: true
// @target: ES5
// @lib: es2015
// mainly to verify indentation of emitted code
function g() { return "g"; }
function* objectLiteral1() {
const x = {
a: 1,
b: yield 2,
c: 3,
}
}
function* objectLiteral2() {
const x = {
a: 1,
[g()]: yield 2,
c: 3,
}
}
function* objectLiteral3() {
const x = {
a: 1,
b: yield 2,
[g()]: 3,
c: 4,
}
}
function* objectLiteral4() {
const x = {
a: 1,
[g()]: 2,
b: yield 3,
c: 4,
}
}
function* objectLiteral5() {
const x = {
a: 1,
[g()]: yield 2,
c: 4,
}
}
function* objectLiteral6() {
const x = {
a: 1,
[yield]: 2,
c: 4,
}
}
function* objectLiteral7() {
const x = {
a: 1,
[yield]: yield 2,
c: 4,
}
}
| {
"end_byte": 927,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es5-yieldFunctionObjectLiterals.ts"
} |
TypeScript/tests/cases/compiler/intersectionConstraintReduction.ts_0_1381 | // @strict: true
// @noEmit: true
type Test1<K1 extends keyof any, K2 extends keyof any> =
MustBeKey<Extract<K1, keyof any> & K1 & K2>;
type Test2<K1 extends keyof any, K2 extends keyof any> =
MustBeKey<K1 & K2 & Extract<K1, keyof any>>;
type MustBeKey<K extends keyof any> = K;
// https://github.com/microsoft/TypeScript/issues/58370
type AnyKey = number | string | symbol;
type ReturnTypeKeyof<Obj extends object> = Obj extends object
? [keyof Obj] extends [never]
? never
: { [Key in keyof Obj as string]-?: () => Key }[string]
: never;
type KeyIfSignatureOfObject<
Obj extends object,
Key extends AnyKey,
ReturnTypeKeys = ReturnTypeKeyof<Obj>,
> = ReturnTypeKeys extends () => Key ? ((() => Key) extends ReturnTypeKeys ? Key : never) : never;
export type Reduced1<Obj extends object, Key extends AnyKey, Value, ObjKeys extends keyof Obj = keyof Obj> =
Key extends KeyIfSignatureOfObject<Obj, Key>
? Key extends ObjKeys
? { [K in Key]: Value }
: never
: never;
export type Reduced2<Obj extends object, Key extends AnyKey, Value, ObjKeys extends keyof Obj = keyof Obj> =
Key extends AnyKey
? Key extends KeyIfSignatureOfObject<Obj, Key>
? Key extends ObjKeys
? { [K in Key]: Value }
: never
: never
: never;
| {
"end_byte": 1381,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/intersectionConstraintReduction.ts"
} |
TypeScript/tests/cases/compiler/declarationEmitDetachedComment1.ts_0_395 | // @target: es5
// @module: commonjs
// @declaration: true
// @removeComments: false
// @filename: test1.ts
/*! Copyright 2015 MyCompany Inc. */
/**
* Hello class
*/
class Hello {
}
// @filename: test2.ts
/* A comment at the top of the file. */
/**
* Hi class
*/
class Hi {
}
// @filename: test3.ts
// A one-line comment at the top of the file.
/**
* Hola class
*/
class Hola {
}
| {
"end_byte": 395,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitDetachedComment1.ts"
} |
TypeScript/tests/cases/compiler/typeReferenceDirectives7.ts_0_387 | // @noImplicitReferences: true
// @traceResolution: true
// @declaration: true
// @typeRoots: /types
// @currentDirectory: /
// local value shadows global - no need to add type reference directive
// @filename: /types/lib/index.d.ts
declare let $: { x: number }
// @filename: /app.ts
/// <reference types="lib"/>
export let $ = 1;
export let x: typeof $;
export let y = () => x | {
"end_byte": 387,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeReferenceDirectives7.ts"
} |
TypeScript/tests/cases/compiler/modularizeLibrary_Dom.iterable.ts_3_152 | @skipLibCheck: true
// @lib: es6,dom,dom.iterable
// @target: es6
for (const element of document.getElementsByTagName("a")) {
element.href;
} | {
"end_byte": 152,
"start_byte": 3,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/modularizeLibrary_Dom.iterable.ts"
} |
TypeScript/tests/cases/compiler/exportStarForValues7.ts_0_194 | // @module: amd
// @filename: file1.ts
export interface Foo { x }
// @filename: file2.ts
export * from "file1"
export var x = 1;
// @filename: file3.ts
export * from "file2"
export var x = 1; | {
"end_byte": 194,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exportStarForValues7.ts"
} |
TypeScript/tests/cases/compiler/destructuringAssignmentWithDefault2.ts_0_512 | // @lib: es2015
// @strictNullChecks: true
const a: { x?: number; y?: number } = { };
let x: number;
// Should not error out
({ x = 0 } = a);
({ x: x = 0} = a);
({ y: x = 0} = a);
// Should be error
({ x = undefined } = a);
({ x: x = undefined } = a);
({ y: x = undefined } = a);
const { x: z1 } = a;
const { x: z2 = 0 } = a;
const { x: z3 = undefined } = a;
declare const r: Iterator<number>;
let done: boolean;
let value;
({ done = false, value } = r.next());
({ done: done = false, value } = r.next()); | {
"end_byte": 512,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/destructuringAssignmentWithDefault2.ts"
} |
TypeScript/tests/cases/compiler/generics4.ts_0_167 | class C<T> { private x: T; }
interface X { f(): string; }
interface Y { f(): boolean; }
var a: C<X>;
var b: C<Y>;
a = b; // Not ok - return types of "f" are different | {
"end_byte": 167,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/generics4.ts"
} |
TypeScript/tests/cases/compiler/APISample_jsdoc.ts_0_4076 | // @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_jsdoc.ts
/*
* Note: This test is a public API sample. The original sources can be found
* at: https://github.com/YousefED/typescript-json-schema
* https://github.com/vega/ts-json-schema-generator
* Please log a "breaking change" issue for any API breaking change affecting this issue
*/
declare var console: any;
import * as ts from "typescript";
// excerpted from https://github.com/YousefED/typescript-json-schema
// (converted from a method and modified; for example, `this: any` to compensate, among other changes)
function parseCommentsIntoDefinition(this: any,
symbol: ts.Symbol,
definition: {description?: string, [s: string]: string | undefined},
otherAnnotations: { [s: string]: true}): void {
if (!symbol) {
return;
}
// the comments for a symbol
let comments = symbol.getDocumentationComment(undefined);
if (comments.length) {
definition.description = comments.map(comment => comment.kind === "lineBreak" ? comment.text : comment.text.trim().replace(/\r\n/g, "\n")).join("");
}
// jsdocs are separate from comments
const jsdocs = symbol.getJsDocTags(this.checker);
jsdocs.forEach(doc => {
// if we have @TJS-... annotations, we have to parse them
const { name, text } = doc;
if (this.userValidationKeywords[name]) {
definition[name] = this.parseValue(text);
} else {
// special annotations
otherAnnotations[doc.name] = true;
}
});
}
// excerpted from https://github.com/vega/ts-json-schema-generator
export interface Annotations {
[name: string]: any;
}
function getAnnotations(this: any, node: ts.Node): Annotations | undefined {
const symbol: ts.Symbol = (node as any).symbol;
if (!symbol) {
return undefined;
}
const jsDocTags: ts.JSDocTagInfo[] = symbol.getJsDocTags(this.checker);
if (!jsDocTags || !jsDocTags.length) {
return undefined;
}
const annotations: Annotations = jsDocTags.reduce((result: Annotations, jsDocTag: ts.JSDocTagInfo) => {
const value = this.parseJsDocTag(jsDocTag);
if (value !== undefined) {
result[jsDocTag.name] = value;
}
return result;
}, {});
return Object.keys(annotations).length ? annotations : undefined;
}
// these examples are artificial and mostly nonsensical
function parseSpecificTags(node: ts.Node) {
if (node.kind === ts.SyntaxKind.Parameter) {
return ts.getJSDocParameterTags(node as ts.ParameterDeclaration);
}
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
const func = node as ts.FunctionDeclaration;
if (ts.hasJSDocParameterTags(func)) {
const flat: ts.JSDocTag[] = [];
for (const tags of func.parameters.map(ts.getJSDocParameterTags)) {
if (tags) flat.push(...tags);
}
return flat;
}
}
}
function getReturnTypeFromJSDoc(node: ts.Node) {
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
return ts.getJSDocReturnType(node);
}
let type = ts.getJSDocType(node);
if (type && type.kind === ts.SyntaxKind.FunctionType) {
return (type as ts.FunctionTypeNode).type;
}
}
function getAllTags(node: ts.Node) {
ts.getJSDocTags(node);
}
function getSomeOtherTags(node: ts.Node) {
const tags: (ts.JSDocTag | undefined)[] = [];
tags.push(ts.getJSDocAugmentsTag(node));
tags.push(ts.getJSDocClassTag(node));
tags.push(ts.getJSDocReturnTag(node));
const type = ts.getJSDocTypeTag(node);
if (type) {
tags.push(type);
}
tags.push(ts.getJSDocTemplateTag(node));
return tags;
}
| {
"end_byte": 4076,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/APISample_jsdoc.ts"
} |
TypeScript/tests/cases/compiler/ParameterList13.ts_0_35 | interface I {
new (public x);
} | {
"end_byte": 35,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ParameterList13.ts"
} |
TypeScript/tests/cases/compiler/arrowFunctionErrorSpan.ts_0_607 | function f(a: () => number) { }
// oneliner
f(() => { });
// multiline, body
f(() => {
});
// multiline 2, body
f(() => {
});
// multiline 3, arrow on a new line
f(()
=> { });
// multiline 4, arguments
f((a,
b,
c,
d) => { });
// single line with a comment
f(/*
*/() => { });
// multi line with a comment
f(/*
*/() => { });
// multi line with a comment 2
f(/*
*/() => {
});
// multi line with a comment 3
f( // comment 1
// comment 2
() =>
// comment 3
{
// comment 4
}
// comment 5
);
// body is not a block
f(_ => 1 +
2);
| {
"end_byte": 607,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrowFunctionErrorSpan.ts"
} |
TypeScript/tests/cases/compiler/inferenceExactOptionalProperties1.ts_0_151 | // @strict: true
// @exactOptionalPropertyTypes: true
// @noEmit: true
type Test1 = { prop?: never } extends { prop?: infer T } ? T : false; // never
| {
"end_byte": 151,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/inferenceExactOptionalProperties1.ts"
} |
TypeScript/tests/cases/compiler/accessInstanceMemberFromStaticMethod01.ts_0_75 | class C {
static foo: string;
bar() {
let k = foo;
}
} | {
"end_byte": 75,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/accessInstanceMemberFromStaticMethod01.ts"
} |
TypeScript/tests/cases/compiler/ClassDeclaration24.ts_0_13 | class any {
} | {
"end_byte": 13,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ClassDeclaration24.ts"
} |
TypeScript/tests/cases/compiler/narrowByClauseExpressionInSwitchTrue2.ts_0_359 | // @strict: true
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/55986
declare const f: 'a' | 'b' | 'c';
switch(true) {
case f === 'a':
case f === 'b':
f;
break
default:
f;
}
f;
switch(true) {
case f === 'a':
f;
case f === 'b':
f;
break
default:
f;
}
f;
| {
"end_byte": 359,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/narrowByClauseExpressionInSwitchTrue2.ts"
} |
TypeScript/tests/cases/compiler/reexportMissingDefault2.ts_0_156 | // @allowSyntheticDefaultImports: true
// @filename: b.ts
export const b = null;
// @filename: a.ts
export { b } from "./b";
export { default } from "./b"; | {
"end_byte": 156,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reexportMissingDefault2.ts"
} |
TypeScript/tests/cases/compiler/fatArrowSelf.ts_0_521 | module Events {
export interface ListenerCallback {
(value:any):void;
}
export class EventEmitter {
public addListener(type:string, listener:ListenerCallback) {
}
}
}
module Consumer {
class EventEmitterConsummer {
constructor (private emitter: Events.EventEmitter) { }
private register() {
this.emitter.addListener('change', (e) => {
this.changed();
});
}
private changed() {
}
}
} | {
"end_byte": 521,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/fatArrowSelf.ts"
} |
TypeScript/tests/cases/compiler/memberAccessMustUseModuleInstances.ts_0_376 | //@module: amd
// @Filename: memberAccessMustUseModuleInstances_0.ts
export class Promise {
static timeout(delay: number): Promise {
return null;
}
}
// @Filename: memberAccessMustUseModuleInstances_1.ts
///<reference path='memberAccessMustUseModuleInstances_0.ts'/>
import WinJS = require('memberAccessMustUseModuleInstances_0');
WinJS.Promise.timeout(10);
| {
"end_byte": 376,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/memberAccessMustUseModuleInstances.ts"
} |
TypeScript/tests/cases/compiler/importNonExportedMember3.ts_0_127 | // @Filename: a.ts
export {}
interface Foo {}
interface Foo {}
namespace Foo {}
// @Filename: b.ts
import { Foo } from './a';
| {
"end_byte": 127,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/importNonExportedMember3.ts"
} |
TypeScript/tests/cases/compiler/declarationMapsOutFile2.ts_0_309 | // @declaration: true
// @declarationMap: true
// @outFile: bundle.js
// @filename: a.ts
class Foo {
doThing(x: {a: number}) {
return {b: x.a};
}
static make() {
return new Foo();
}
}
// @filename: index.ts
const c = new Foo();
c.doThing({a: 42});
let x = c.doThing({a: 12});
| {
"end_byte": 309,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationMapsOutFile2.ts"
} |
TypeScript/tests/cases/compiler/inferentialTypingWithFunctionTypeSyntacticScenarios.ts_0_666 | // @allowUnreachableCode: true
declare function map<T, U>(array: T, func: (x: T) => U): U;
declare function identity<V>(y: V): V;
var s: string;
// dotted name
var dottedIdentity = { x: identity };
s = map("", dottedIdentity.x);
// index expression
s = map("", dottedIdentity['x']);
// function call
s = map("", (() => identity)());
// construct
interface IdentityConstructor {
new (): typeof identity;
}
var ic: IdentityConstructor;
s = map("", new ic());
// assignment
var t;
s = map("", t = identity);
// type assertion
s = map("", <typeof identity>identity);
// parenthesized expression
s = map("", (identity));
// comma
s = map("", ("", identity)); | {
"end_byte": 666,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/inferentialTypingWithFunctionTypeSyntacticScenarios.ts"
} |
TypeScript/tests/cases/compiler/varianceRepeatedlyPropegatesWithUnreliableFlag.ts_0_464 | type A = { a: number };
type B = { b: number };
type X<T> = ({ [K in keyof T]: T[K] } & Record<string, void>)[keyof T];
type P1<T> = { data: X<T> };
type P2<T> = { data: X<T> };
interface I<T> {
fn<K extends keyof T>(p1: P1<Pick<T, K>>, p2: P2<Pick<T, K>>): void;
}
const i: I<A & B> = null as any;
const p2: P2<A> = null as any;
// Commenting out the below line will remove the error on the `const _i: I<A> = i;`
i.fn(null as any, p2);
const _i: I<A> = i; | {
"end_byte": 464,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/varianceRepeatedlyPropegatesWithUnreliableFlag.ts"
} |
TypeScript/tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts_0_315 | // @module: amd
// @traceResolution: true
// baseurl is defined in tsconfig.json
// paths has errors
// @filename: root/tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"*1*": [ "*2*" ]
}
}
}
// @filename: root/src/folder1/file1.ts
export var x = 1; | {
"end_byte": 315,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts"
} |
TypeScript/tests/cases/compiler/incorrectNumberOfTypeArgumentsDuringErrorReporting.ts_0_272 | interface ObjA {
y?:string,
}
interface ObjB {[key:string]:any}
interface Opts<A, B> {a:A, b:B}
const fn = <
A extends ObjA,
B extends ObjB = ObjB
>(opts:Opts<A, B>):string => 'Z'
interface MyObjA {
x:string,
}
fn<MyObjA>({
a: {x: 'X', y: 'Y'},
b: {},
})
| {
"end_byte": 272,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/incorrectNumberOfTypeArgumentsDuringErrorReporting.ts"
} |
TypeScript/tests/cases/compiler/sourceMapValidationFunctionPropertyAssignment.ts_0_40 | // @sourcemap: true
var x = { n() { } }; | {
"end_byte": 40,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/sourceMapValidationFunctionPropertyAssignment.ts"
} |
TypeScript/tests/cases/compiler/dottedModuleName.ts_0_222 | module M {
export module N {
export function f(x:number)=>2*x;
export module X.Y.Z {
export var v2=f(v);
}
}
}
module M.N {
export module X {
export module Y.Z {
export var v=f(10);
}
}
}
| {
"end_byte": 222,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/dottedModuleName.ts"
} |
TypeScript/tests/cases/compiler/unusedTypeParameters_infer.ts_0_94 | // @noUnusedParameters: true
type Length<T> = T extends ArrayLike<infer U> ? number : never;
| {
"end_byte": 94,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedTypeParameters_infer.ts"
} |
TypeScript/tests/cases/compiler/arrayFind.ts_0_574 | // @lib: es2015
// test fix for #18112, type guard predicates should narrow returned element
function isNumber(x: any): x is number {
return typeof x === "number";
}
const arrayOfStringsNumbersAndBooleans = ["string", false, 0, "strung", 1, true];
const foundNumber: number | undefined = arrayOfStringsNumbersAndBooleans.find(isNumber);
const readonlyArrayOfStringsNumbersAndBooleans = arrayOfStringsNumbersAndBooleans as ReadonlyArray<string | number | boolean>;
const readonlyFoundNumber: number | undefined = readonlyArrayOfStringsNumbersAndBooleans.find(isNumber);
| {
"end_byte": 574,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrayFind.ts"
} |
TypeScript/tests/cases/compiler/invalidOptionalChainFromNewExpression.ts_0_65 | class A {
b() {}
}
new A?.b() // error
new A()?.b() // ok
| {
"end_byte": 65,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/invalidOptionalChainFromNewExpression.ts"
} |
TypeScript/tests/cases/compiler/es2015modulekindWithES6Target.ts_0_185 | // @target: es6
// @sourcemap: false
// @declaration: false
// @module: es2015
export default class A
{
constructor ()
{
}
public B()
{
return 42;
}
} | {
"end_byte": 185,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es2015modulekindWithES6Target.ts"
} |
TypeScript/tests/cases/compiler/internalAliasInterfaceInsideTopLevelModuleWithoutExport.ts_0_122 | //@module: amd
// @declaration: true
export module a {
export interface I {
}
}
import b = a.I;
export var x: b;
| {
"end_byte": 122,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/internalAliasInterfaceInsideTopLevelModuleWithoutExport.ts"
} |
TypeScript/tests/cases/compiler/jsFileCompilationReturnTypeSyntaxOfFunction.ts_0_61 | // @allowJs: true
// @filename: a.js
function F(): number { } | {
"end_byte": 61,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsFileCompilationReturnTypeSyntaxOfFunction.ts"
} |
TypeScript/tests/cases/compiler/unionOfClassCalls.ts_0_1593 | // @strict: true
// from https://github.com/microsoft/TypeScript/issues/30717
declare class Test<T> {
obj: T;
get<K extends keyof T>(k: K): T[K];
}
interface A { t: "A" }
interface B { t: "B" }
declare const tmp: Test<A> | Test<B>;
switch (tmp.get('t')) {
case 'A': break;
case 'B': break;
}
// from https://github.com/microsoft/TypeScript/issues/36390
const arr: number[] | string[] = []; // Works with Array<number | string>
const arr1: number[] = [];
const arr2: string[] = [];
arr.map((a: number | string, index: number) => {
return index
})
// This case still doesn't work because `reduce` has multiple overloads :(
arr.reduce((acc: Array<string>, a: number | string, index: number) => {
return []
}, [])
arr.forEach((a: number | string, index: number) => {
return index
})
arr1.map((a: number, index: number) => {
return index
})
arr1.reduce((acc: number[], a: number, index: number) => {
return [a]
}, [])
arr1.forEach((a: number, index: number) => {
return index
})
arr2.map((a: string, index: number) => {
return index
})
arr2.reduce((acc: string[], a: string, index: number) => {
return []
}, [])
arr2.forEach((a: string, index: number) => {
return index
})
// from https://github.com/microsoft/TypeScript/issues/36307
declare class Foo {
doThing(): Promise<this>
}
declare class Bar extends Foo {
bar: number;
}
declare class Baz extends Foo {
baz: number;
}
declare var a: Bar | Baz;
// note, you must annotate `result` for now
a.doThing().then((result: Bar | Baz) => {
// whatever
});
| {
"end_byte": 1593,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unionOfClassCalls.ts"
} |
TypeScript/tests/cases/compiler/typeParameterConstrainedToOuterTypeParameter2.ts_0_144 | interface A<T> {
foo<U extends T>(x: A<A<U>>)
}
interface B<T> {
foo<U extends T>(x: B<B<U>>)
}
var a: A<string>
var b: B<string> = a; | {
"end_byte": 144,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/typeParameterConstrainedToOuterTypeParameter2.ts"
} |
TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody1.ts_0_20 | var v = a => <any>{} | {
"end_byte": 20,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrowFunctionWithObjectLiteralBody1.ts"
} |
TypeScript/tests/cases/compiler/switchComparableCompatForBrands.ts_0_172 | class MyBrand
{
private _a: number;
}
function test(strInput: string & MyBrand) {
switch(strInput)
{
case "a":
return 1;
}
return 0;
}
| {
"end_byte": 172,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/switchComparableCompatForBrands.ts"
} |
TypeScript/tests/cases/compiler/jsFileCompilationBindDeepExportsAssignment.ts_0_92 | // @allowJs: true
// @noEmit: true
// @checkJs: true
// @filename: a.js
exports.a.b.c = 0;
| {
"end_byte": 92,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsFileCompilationBindDeepExportsAssignment.ts"
} |
TypeScript/tests/cases/compiler/discriminantsAndPrimitives.ts_0_1407 | // @strictNullChecks: true
// Repro from #10257 plus other tests
interface Foo {
kind: "foo";
name: string;
}
interface Bar {
kind: "bar";
length: string;
}
function f1(x: Foo | Bar | string) {
if (typeof x !== 'string') {
switch(x.kind) {
case 'foo':
x.name;
}
}
}
function f2(x: Foo | Bar | string | undefined) {
if (typeof x === "object") {
switch(x.kind) {
case 'foo':
x.name;
}
}
}
function f3(x: Foo | Bar | string | null) {
if (x && typeof x !== "string") {
switch(x.kind) {
case 'foo':
x.name;
}
}
}
function f4(x: Foo | Bar | string | number | null) {
if (x && typeof x === "object") {
switch(x.kind) {
case 'foo':
x.name;
}
}
}
// Repro from #31319
const enum EnumTypeNode {
Pattern = "Pattern",
Disjunction = "Disjunction",
}
type NodeA = Disjunction | Pattern;
interface NodeBase {
type: NodeA["type"]
}
interface Disjunction extends NodeBase {
type: EnumTypeNode.Disjunction
alternatives: string[]
}
interface Pattern extends NodeBase {
type: EnumTypeNode.Pattern
elements: string[]
}
let n!: NodeA
if (n.type === "Disjunction") {
n.alternatives.slice()
}
else {
n.elements.slice() // n should be narrowed to Pattern
}
| {
"end_byte": 1407,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/discriminantsAndPrimitives.ts"
} |
TypeScript/tests/cases/compiler/constWithNonNull.ts_0_60 | // Fixes #21848
declare const x: number | undefined;
x!++;
| {
"end_byte": 60,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/constWithNonNull.ts"
} |
TypeScript/tests/cases/compiler/collisionSuperAndParameter1.ts_0_120 | class Foo {
}
class Foo2 extends Foo {
x() {
var lambda = (_super: number) => { // Error
}
}
} | {
"end_byte": 120,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/collisionSuperAndParameter1.ts"
} |
TypeScript/tests/cases/compiler/arrayAssignmentTest2.ts_0_1384 | interface I1 {
IM1():void[];
}
class C1 implements I1 {
IM1():void[] {return null;}
C1M1():C1[] {return null;}
}
class C2 extends C1 {
C2M1():C2[] { return null;}
}
class C3 {
CM3M1() { return 3;}
}
/*
This behaves unexpectedly with the following types:
Type 1 of any[]:
* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].
* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.
*/
var a1 : any = null;
var c1 : C1 = new C1();
var i1 : I1 = c1;
var c2 : C2 = new C2();
var c3 : C3 = new C3();
var o1 = {one : 1};
var f1 = function () { return new C1();}
var arr_any: any[] = [];
var arr_i1: I1[] = [];
var arr_c1: C1[] = [];
var arr_c2: C2[] = [];
var arr_i1_2: I1[] = [];
var arr_c1_2: C1[] = [];
var arr_c2_2: C2[] = [];
var arr_c3: C3[] = [];
// "clean up error" occurs at this point
arr_c3 = arr_c2_2; // should be an error - is
arr_c3 = arr_c1_2; // should be an error - is
arr_c3 = arr_i1_2; // should be an error - is
arr_any = f1; // should be an error - is
arr_any = function () { return null;} // should be an error - is
arr_any = o1; // should be an error - is
arr_any = a1; // should be ok - is
arr_any = c1; // should be an error - is
arr_any = c2; // should be an error - is
arr_any = c3; // should be an error - is
arr_any = i1; // should be an error - is
| {
"end_byte": 1384,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/arrayAssignmentTest2.ts"
} |
TypeScript/tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx_0_1232 | // @jsx: react
declare var React: any;
var justElement1 = <a:element />;
var justElement2 = <a:element></a:element>;
var justElement3 = <a:element attr={"value"}></a:element>;
var justElement4 = <a:element>{"text"}</a:element>;
var justElement5 = <a:element attr={"value"}>{"text"}</a:element>;
var tooManySeparators1 = <a:ele:ment />;
var tooManySeparators2 = <a:ele:ment></a:ele:ment>;
var tooManySeparators3 = <a:ele:ment attr={"value"}></a:ele:ment>;
var tooManySeparators4 = <a:ele:ment>{"text"}</a:ele:ment>;
var tooManySeparators5 = <a:ele:ment attr={"value"}>{"text"}</a:ele:ment>;
var justAttribute1 = <element a:attr={"value"} />;
var justAttribute2 = <element a:attr={"value"}></element>;
var justAttribute3 = <element a:attr={"value"}>{"text"}</element>;
var both1 = <a:element a:attr={"value"} />;
var both2 = <a:element k:attr={"value"}></a:element>;
var both3 = <a:element a:attr={"value"}>{"text"}</a:element>;
var endOfIdent1 = <a: attr={"value"} />;
var endOfIdent2 = <a attr:={"value"} />;
var beginOfIdent1 = <:a attr={"value"} />;
var beginOfIdent2 = <a :attr={"value"} />;
var upcaseComponent1 = <ns:Upcase />; // Parsed as intrinsic
var upcaseComponent2 = <Upcase:element />; // Parsed as instrinsic
| {
"end_byte": 1232,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxNamespacePrefixInNameReact.tsx"
} |
TypeScript/tests/cases/compiler/functionWithDefaultParameterWithNoStatements11.ts_0_69 | var v: any[];
function foo(a = v[0]) { }
function bar(a = v[0]) {
} | {
"end_byte": 69,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/functionWithDefaultParameterWithNoStatements11.ts"
} |
TypeScript/tests/cases/compiler/deprecatedBool.ts_0_36 | var b4: boolean;
var bool: boolean;
| {
"end_byte": 36,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/deprecatedBool.ts"
} |
TypeScript/tests/cases/compiler/inheritance1.ts_0_781 | class Control {
private state: any;
}
interface SelectableControl extends Control {
select(): void;
}
class Button extends Control implements SelectableControl {
select() { }
}
class TextBox extends Control {
select() { }
}
class ImageBase extends Control implements SelectableControl{
}
class Image1 extends Control {
}
class Locations implements SelectableControl {
select() { }
}
class Locations1 {
select() { }
}
var sc: SelectableControl;
var c: Control;
var b: Button;
sc = b;
c = b;
b = sc;
b = c;
var t: TextBox;
sc = t;
c = t;
t = sc;
t = c;
var i: ImageBase;
sc = i;
c = i;
i = sc;
i = c;
var i1: Image1;
sc = i1;
c = i1;
i1 = sc;
i1 = c;
var l: Locations;
sc = l;
c = l;
l = sc;
l = c;
var l1: Locations1;
sc = l1;
c = l1;
l1 = sc;
l1 = c; | {
"end_byte": 781,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/inheritance1.ts"
} |
TypeScript/tests/cases/compiler/inferFromGenericFunctionReturnTypes2.ts_0_2472 | type Mapper<T, U> = (x: T) => U;
declare function wrap<T, U>(cb: Mapper<T, U>): Mapper<T, U>;
declare function arrayize<T, U>(cb: Mapper<T, U>): Mapper<T, U[]>;
declare function combine<A, B, C>(f: (x: A) => B, g: (x: B) => C): (x: A) => C;
declare function foo(f: Mapper<string, number>): void;
let f1: Mapper<string, number> = s => s.length;
let f2: Mapper<string, number> = wrap(s => s.length);
let f3: Mapper<string, number[]> = arrayize(wrap(s => s.length));
let f4: Mapper<string, boolean> = combine(wrap(s => s.length), wrap(n => n >= 10));
foo(wrap(s => s.length));
let a1 = ["a", "b"].map(s => s.length);
let a2 = ["a", "b"].map(wrap(s => s.length));
let a3 = ["a", "b"].map(wrap(arrayize(s => s.length)));
let a4 = ["a", "b"].map(combine(wrap(s => s.length), wrap(n => n > 10)));
let a5 = ["a", "b"].map(combine(identity, wrap(s => s.length)));
let a6 = ["a", "b"].map(combine(wrap(s => s.length), identity));
// This is a contrived class. We could do the same thing with Observables, etc.
class SetOf<A> {
_store: A[];
add(a: A) {
this._store.push(a);
}
transform<B>(transformer: (a: SetOf<A>) => SetOf<B>): SetOf<B> {
return transformer(this);
}
forEach(fn: (a: A, index: number) => void) {
this._store.forEach((a, i) => fn(a, i));
}
}
function compose<A, B, C, D, E>(
fnA: (a: SetOf<A>) => SetOf<B>,
fnB: (b: SetOf<B>) => SetOf<C>,
fnC: (c: SetOf<C>) => SetOf<D>,
fnD: (c: SetOf<D>) => SetOf<E>,
):(x: SetOf<A>) => SetOf<E>;
/* ... etc ... */
function compose<T>(...fns: ((x: T) => T)[]): (x: T) => T {
return (x: T) => fns.reduce((prev, fn) => fn(prev), x);
}
function map<A, B>(fn: (a: A) => B): (s: SetOf<A>) => SetOf<B> {
return (a: SetOf<A>) => {
const b: SetOf<B> = new SetOf();
a.forEach(x => b.add(fn(x)));
return b;
}
}
function filter<A>(predicate: (a: A) => boolean): (s: SetOf<A>) => SetOf<A> {
return (a: SetOf<A>) => {
const result = new SetOf<A>();
a.forEach(x => {
if (predicate(x)) result.add(x);
});
return result;
}
}
const testSet = new SetOf<number>();
testSet.add(1);
testSet.add(2);
testSet.add(3);
const t1 = testSet.transform(
compose(
filter(x => x % 1 === 0),
map(x => x + x),
map(x => x + '!!!'),
map(x => x.toUpperCase())
)
)
declare function identity<T>(x: T): T;
const t2 = testSet.transform(
compose(
filter(x => x % 1 === 0),
identity,
map(x => x + '!!!'),
map(x => x.toUpperCase())
)
)
| {
"end_byte": 2472,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/inferFromGenericFunctionReturnTypes2.ts"
} |
TypeScript/tests/cases/compiler/unusedVariablesinForLoop3.ts_0_118 | //@noUnusedLocals:true
//@noUnusedParameters:true
function f1 () {
for (const elem of ["a", "b", "c"]) {
}
} | {
"end_byte": 118,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedVariablesinForLoop3.ts"
} |
TypeScript/tests/cases/compiler/errorForBareSpecifierWithImplicitModuleResolutionNone.ts_0_131 | // This would be classed as moduleResolutionKind: Classic
// @module: es2015
import { thing } from "non-existent-module";
thing()
| {
"end_byte": 131,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/errorForBareSpecifierWithImplicitModuleResolutionNone.ts"
} |
TypeScript/tests/cases/compiler/implementsIncorrectlyNoAssertion.ts_0_163 | declare class Foo {
x: string;
}
declare class Bar {
y: string;
}
type Wrapper = Foo & Bar;
class Baz implements Wrapper {
x: number;
y: string;
}
| {
"end_byte": 163,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/implementsIncorrectlyNoAssertion.ts"
} |
TypeScript/tests/cases/compiler/aliasOnMergedModuleInterface.ts_0_492 | //@module: commonjs
// @Filename: aliasOnMergedModuleInterface_0.ts
declare module "foo"
{
module B {
export interface A {
}
}
interface B {
bar(name: string): B.A;
}
export = B;
}
// @Filename: aliasOnMergedModuleInterface_1.ts
///<reference path='aliasOnMergedModuleInterface_0.ts' />
import foo = require("foo")
var z: foo;
z.bar("hello"); // This should be ok
var x: foo.A = foo.bar("hello"); // foo.A should be ok but foo.bar should be error
| {
"end_byte": 492,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/aliasOnMergedModuleInterface.ts"
} |
TypeScript/tests/cases/compiler/homomorphicMappedTypeIntersectionAssignability.ts_0_238 | // @strict: true
function f<TType>(
a: { weak?: string } & Readonly<TType> & { name: "ok" },
b: Readonly<TType & { name: string }>,
c: Readonly<TType> & { name: string }) {
c = a; // Works
b = a; // Should also work
}
| {
"end_byte": 238,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/homomorphicMappedTypeIntersectionAssignability.ts"
} |
TypeScript/tests/cases/compiler/unusedSingleParameterInContructor.ts_0_131 | //@noUnusedLocals:true
//@noUnusedParameters:true
class Dummy {
constructor(person: string) {
var unused = 20;
}
} | {
"end_byte": 131,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedSingleParameterInContructor.ts"
} |
TypeScript/tests/cases/compiler/methodContainingLocalFunction.ts_0_1064 | // @target: ES5
// The first case here (BugExhibition<T>) caused a crash. Try with different permutations of features.
class BugExhibition<T> {
public exhibitBug() {
function localFunction() { }
var x: { (): void; };
x = localFunction;
}
}
class BugExhibition2<T> {
private static get exhibitBug() {
function localFunction() { }
var x: { (): void; };
x = localFunction;
return null;
}
}
class BugExhibition3<T> {
public exhibitBug() {
function localGenericFunction<U>(u?: U) { }
var x: { (): void; };
x = localGenericFunction;
}
}
class C {
exhibit() {
var funcExpr = <U>(u?: U) => { };
var x: { (): void; };
x = funcExpr;
}
}
module M {
export function exhibitBug() {
function localFunction() { }
var x: { (): void; };
x = localFunction;
}
}
enum E {
A = (() => {
function localFunction() { }
var x: { (): void; };
x = localFunction;
return 0;
})()
} | {
"end_byte": 1064,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/methodContainingLocalFunction.ts"
} |
TypeScript/tests/cases/compiler/constEnumExternalModule.ts_0_131 | //@module: amd
//@Filename: m1.ts
const enum E {
V = 100
}
export = E
//@Filename: m2.ts
import A = require('m1')
var v = A.V; | {
"end_byte": 131,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/constEnumExternalModule.ts"
} |
TypeScript/tests/cases/compiler/jsxInExtendsClause.tsx_0_439 | // @jsx: react
// https://github.com/Microsoft/TypeScript/issues/13157
declare namespace React {
interface ComponentClass<P> { new (): Component<P, {}>; }
class Component<A, B> {}
}
declare function createComponentClass<P>(factory: () => React.ComponentClass<P>): React.ComponentClass<P>;
class Foo extends createComponentClass(() => class extends React.Component<{}, {}> {
render() {
return <span>Hello, world!</span>;
}
}) {} | {
"end_byte": 439,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxInExtendsClause.tsx"
} |
TypeScript/tests/cases/compiler/ClassDeclaration10.ts_0_39 | class C {
constructor();
foo();
} | {
"end_byte": 39,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/ClassDeclaration10.ts"
} |
TypeScript/tests/cases/compiler/assignmentCompatability35.ts_0_347 | 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:{[index:number]:number;};;
export var __val__aa = aa;
}
__test2__.__val__aa = __test1__.__val__obj4 | {
"end_byte": 347,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/assignmentCompatability35.ts"
} |
TypeScript/tests/cases/compiler/parseCommaSeparatedNewlineNew.ts_0_8 | (a,
new) | {
"end_byte": 8,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/parseCommaSeparatedNewlineNew.ts"
} |
TypeScript/tests/cases/compiler/es2018ObjectAssign.ts_0_115 | // @target: es2018
const test = Object.assign({}, { test: true });
declare const p: Promise<number>;
p.finally(); | {
"end_byte": 115,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/es2018ObjectAssign.ts"
} |
TypeScript/tests/cases/compiler/recursiveBaseConstructorCreation2.ts_0_166 | declare class base
{
}
declare class abc extends base
{
foo: xyz;
}
declare class xyz extends abc
{
}
var bar = new xyz(); // Error: Invalid 'new' expression.
| {
"end_byte": 166,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/recursiveBaseConstructorCreation2.ts"
} |
TypeScript/tests/cases/compiler/duplicateObjectLiteralProperty.ts_0_268 | // @target: ES5
var x = {
a: 1,
b: true, // OK
a: 56, // Duplicate
\u0061: "ss", // Duplicate
a: {
c: 1,
"c": 56, // Duplicate
}
};
var y = {
get a() { return 0; },
set a(v: number) { },
get a() { return 0; }
};
| {
"end_byte": 268,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/duplicateObjectLiteralProperty.ts"
} |
TypeScript/tests/cases/compiler/checkJsdocTypeTagOnExportAssignment6.ts_0_310 | // @allowJs: true
// @checkJs: true
// @outDir: ./out
// @filename: checkJsdocTypeTagOnExportAssignment6.js
// @Filename: a.js
/**
* @typedef {Object} Foo
* @property {number} a
* @property {number} b
*/
/** @type {Foo} */
export default { a: 1, b: 1, c: 1 };
// @Filename: b.js
import a from "./a";
a;
| {
"end_byte": 310,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkJsdocTypeTagOnExportAssignment6.ts"
} |
TypeScript/tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts_0_1050 | //@noimplicitany: true
// this should be errors
var arg0 = null; // error at "arg0"
var anyArray = [null, undefined]; // error at array literal
var objL: { v; w; } // error at "y,z"
var funcL: (y2) => number;
function temp1(arg1) { } // error at "temp1"
function testFunctionExprC(subReplace: (s: string, ...arg: any[]) => string) { }
function testFunctionExprC2(eq: (v1: any, v2: any) => number) { };
function testObjLiteral(objLit: { v: any; w: any }) { };
function testFuncLiteral(funcLit: (y2) => number) { };
// this should not be an error
testFunctionExprC2((v1, v2) => 1);
testObjLiteral(objL);
testFuncLiteral(funcL);
var k = temp1(null);
var result = temp1(arg0);
var result1 = temp1(anyArray);
function noError(variable: any, array?: any) { }
noError(null, []);
noError(undefined, <any>[]);
noError(null, [null, undefined]);
noError(undefined, anyArray);
class C {
constructor(emtpyArray: any, variable: any) {
}
}
var newC = new C([], undefined);
var newC1 = new C([], arg0);
var newC2 = new C(<any>[], null)
| {
"end_byte": 1050,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts"
} |
TypeScript/tests/cases/compiler/recursiveConditionalCrash3.ts_0_4441 | // #43529
export {}
/**
*
* Some helper Types and Interfaces..
*
*/
export type CanBeExpanded<T extends object = object, D = string> = {
value: T
default: D
}
interface Base {
}
interface User extends Base {
id: string,
role: CanBeExpanded<Role>,
note: string,
}
interface Role extends Base {
id: string,
user: CanBeExpanded<User>,
x: string
}
// This interface will be expanded in circular way.
interface X extends Base {
id: string,
name: string,
user: CanBeExpanded<User>,
role: CanBeExpanded<Role>
roles: CanBeExpanded<Role[]>
}
type Join<K, P> = K extends string | number ?
P extends string | number ?
`${K}${"" extends P ? "" : "."}${P}`
: never : never;
type PrefixWith<P, S, C = '.'> = P extends '' ? `${string & S}` : `${string & P}${string & C}${string & S}`
type SplitWithAllPossibleCombinations<S extends string, D extends string> =
string extends S ? string :
S extends '' ? '' :
S extends `${infer T}${D}${infer U}` ?
T | Join<T, SplitWithAllPossibleCombinations<U, D>>
: S;
/**
* This function will return all possibile keys that can be expanded on T, only to the N deep level
*/
type KeysCanBeExpanded_<T, N extends number, Depth extends number[]> = N extends Depth['length'] ? never :
T extends CanBeExpanded ?
KeysCanBeExpanded_<T['value'], N, Depth> :
T extends Array<infer U> ? KeysCanBeExpanded_<U, N, Depth> :
T extends object ?
{
[K in keyof T ] :
T[K] extends object ?
K extends string | number
? `${K}` | Join<`${K}`, KeysCanBeExpanded_<T[K], N, [1, ...Depth]>>
: never
: never
}[keyof T]
:
never
export type KeysCanBeExpanded<T, N extends number = 4> = KeysCanBeExpanded_<T, N, []>
/**
* Expand keys on `O` based on `Keys` parameter.
*/
type Expand__<O, Keys, P extends string, N extends number , Depth extends unknown[] > =
N extends Depth['length'] ?
O extends CanBeExpanded ?
O['default'] :
O :
O extends CanBeExpanded ?
Expand__<O[P extends Keys ? 'value' : 'default'], Keys, P, N, Depth> :
O extends Array<infer U> ?
Expand__<U, Keys, P, N, Depth>[]
: O extends object ?
{
[K in keyof O]-?: Expand__<O[K], Keys, PrefixWith<P, K>, N, [1, ...Depth]>
}
: O
type SplitAC<K> = SplitWithAllPossibleCombinations<K extends string ? K : '', '.'> extends infer Ko ? Ko : ''
type Expand_<T, K, N extends number = 4> = Expand__<T, SplitAC<K>, '', N, []>
type AllKeys<T, N extends number = 4> = KeysCanBeExpanded<T, N> extends infer R ? R : never
/**
* If I open the popup, (pointing with the mouse on the Expand), the compiler shows the type Expand, expanded as expected.
*
* It's fast and it doesn't use additional memory
*
*/
export type Expand<T extends object, K extends AllKeys<T, N> = never, N extends number = 4> = Expand_<T, K, N>
/**
* These two functions work as charm, also they are superfast and as expected they don't use additional Memory
*/
let y1: Expand<X>
let y2: Expand<X, 'user.role.user.role'>
/**
*
* ... nevertheless when I need to use the Expand in other Types, as the following examples, the popup show "loading..." and without show any information and
* the Memory Heap grows to 1.2gb (in my case) every time... You can see it opening the Chrome DevTools and check the memory Tab.
*
* *******
* I think this is causing "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory"
* on my project during the `yarn start`.
* *******
*
*/
type UseQueryOptions<T extends Base, K extends AllKeys<T, 4> > = Expand<T, K>
type UseQueryOptions2<T , K > = Expand_<T, K>
type UseQueryOptions3<T , K > = Expand_<T, K> extends infer O ? O : never
type ExpandResult<T,K> = Expand_<T, K> extends infer O ? O : never
type UseQueryOptions4<T , K > = ExpandResult<T,K>
/**
* but as you can see here, the expansion of Interface X it's still working.
*
* If a memory is still high, it may need some seconds to show popup.
*
*/
let t: UseQueryOptions<X, 'role.user.role'>
| {
"end_byte": 4441,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/recursiveConditionalCrash3.ts"
} |
TypeScript/tests/cases/compiler/sliceResultCast.ts_0_93 | declare var x: [number, string] | [number, string, string];
x.slice(1) as readonly string[]; | {
"end_byte": 93,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/sliceResultCast.ts"
} |
TypeScript/tests/cases/compiler/pathsValidation5.ts_0_299 | // @noTypesAndSymbols: true
// @Filename: tsconfig.json
{
"compilerOptions": {
"traceResolution": true,
"paths": {
"@interface/*": ["src/interface/*"],
"@blah": ["blah"],
"@humbug/*": ["*/generated"]
}
}
}
// @filename: src/main.ts
import 'someModule'; | {
"end_byte": 299,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/pathsValidation5.ts"
} |
TypeScript/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts_0_321 | // @declaration: true
var [...a5] = [1, 2, 3];
var [x14, ...a6] = [1, 2, 3];
var [x15, y15, ...a7] = [1, 2, 3];
var [x16, y16, z16, ...a8] = [1, 2, 3];
var [...a9] = [1, "hello", true];
var [x17, ...a10] = [1, "hello", true];
var [x18, y18, ...a12] = [1, "hello", true];
var [x19, y19, z19, ...a13] = [1, "hello", true]; | {
"end_byte": 321,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts"
} |
TypeScript/tests/cases/compiler/declarationEmitMappedTypePropertyFromNumericStringKey.ts_0_136 | // @declaration: true
export const f = (<T>(arg: {[K in keyof T]: T[K] | string}) => arg)({'0': 0}); // Original prop uses string syntax | {
"end_byte": 136,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declarationEmitMappedTypePropertyFromNumericStringKey.ts"
} |
TypeScript/tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts_0_92 | declare module "m1" {
var a: number
var b: number;
export = a;
export = b;
} | {
"end_byte": 92,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts"
} |
TypeScript/tests/cases/compiler/contextualSignatureInArrayElementLibEs2015.ts_0_291 | // @strict: true
// @noEmit: true
// @lib: es2015
// See: https://github.com/microsoft/TypeScript/pull/53280#discussion_r1138684984
declare function test(
arg: Record<string, (arg: string) => void> | Array<(arg: number) => void>
): void;
test([
(arg) => {
arg; // number
},
]);
| {
"end_byte": 291,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/contextualSignatureInArrayElementLibEs2015.ts"
} |
TypeScript/tests/cases/compiler/destructuringTuple.ts_0_334 | // @strict: true
declare var tuple: [boolean, number, ...string[]];
const [a, b, c, ...rest] = tuple;
declare var receiver: typeof tuple;
[...receiver] = tuple;
// Repros from #32140
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
const [oops2] = [1, 2, 3].reduce((acc: number[], e) => acc.concat(e), []);
| {
"end_byte": 334,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/destructuringTuple.ts"
} |
TypeScript/tests/cases/compiler/declFileEnumUsedAsValue.ts_0_64 | // @declaration: true
enum e {
a,
b,
c
}
var x = e; | {
"end_byte": 64,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declFileEnumUsedAsValue.ts"
} |
TypeScript/tests/cases/compiler/contextualSignatureInstatiationCovariance.ts_0_495 | interface Animal { x }
interface TallThing { x2 }
interface Giraffe extends Animal, TallThing { y }
var f2: <T extends Giraffe>(x: T, y: T) => void;
var g2: (a: Animal, t: TallThing) => void;
g2 = f2; // While neither Animal nor TallThing satisfy the constraint, T is at worst a Giraffe and compatible with both via covariance.
var h2: (a1: Animal, a2: Animal) => void;
h2 = f2; // Animal does not satisfy the constraint, but T is at worst a Giraffe and compatible with Animal via covariance. | {
"end_byte": 495,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/contextualSignatureInstatiationCovariance.ts"
} |
TypeScript/tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts_0_301 | // @strictNullChecks: true
// Repro from #12529
class A {
readonly kind = "A"; // (property) A.kind: "A"
}
class B {
readonly kind = "B"; // (property) B.kind: "B"
}
function f(value: A | B): number {
switch(value.kind) {
case "A": return 0;
case "B": return 1;
}
} | {
"end_byte": 301,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts"
} |
TypeScript/tests/cases/compiler/shorthand-property-es5-es6.ts_0_146 | // @target: ES5
// @module: ES6
// @declaration: true
// @filename: test.ts
import {foo} from './foo';
const baz = 42;
const bar = { foo, baz };
| {
"end_byte": 146,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/shorthand-property-es5-es6.ts"
} |
TypeScript/tests/cases/compiler/collisionCodeGenModuleWithMethodChildren.ts_0_385 | module M {
export var x = 3;
class c {
fn(M, p = x) { }
}
}
module M {
class d {
fn2() {
var M;
var p = x;
}
}
}
module M {
class e {
fn3() {
function M() {
var p = x;
}
}
}
}
module M { // Shouldnt bn _M
class f {
M() {
}
}
} | {
"end_byte": 385,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/collisionCodeGenModuleWithMethodChildren.ts"
} |
TypeScript/tests/cases/compiler/restParameterAssignmentCompatibility.ts_3_713 | ass T {
m(...p3) {
}
}
class S {
m(p1, p2) {
}
}
var t: T;
var s: S;
// M is a non - specialized call or construct signature and S' contains a call or construct signature N where,
// the number of non-optional parameters in N is less than or equal to the total number of parameters in M,
t = s; // Should be valid (rest params correspond to an infinite expansion of parameters)
class T1 {
m(p1?, p2?) {
}
}
var t1: T1;
// When comparing call or construct signatures, parameter names are ignored and rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type.
t1 = s; // Similar to above, but optionality does not matter here. | {
"end_byte": 713,
"start_byte": 3,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/restParameterAssignmentCompatibility.ts"
} |
TypeScript/tests/cases/compiler/reverseMappedUnionInference.ts_0_1311 | // @strict: true
// @noEmit: true
interface AnyExtractor<Result> {
matches: (node: any) => boolean;
extract: (node: any) => Result | undefined;
}
interface Extractor<T, Result> {
matches: (node: unknown) => node is T;
extract: (node: T) => Result | undefined;
}
declare function createExtractor<T, Result>(params: {
matcher: (node: unknown) => node is T;
extract: (node: T) => Result;
}): Extractor<T, Result>;
interface Identifier {
kind: "identifier";
name: string;
}
declare function isIdentifier(node: unknown): node is Identifier;
const identifierExtractor = createExtractor({
matcher: isIdentifier,
extract: (node) => {
return {
node,
kind: "identifier" as const,
value: node.name,
};
},
});
interface StringLiteral {
kind: "stringLiteral";
value: string;
}
declare function isStringLiteral(node: unknown): node is StringLiteral;
const stringExtractor = createExtractor({
matcher: isStringLiteral,
extract: (node) => {
return {
node,
kind: "string" as const,
value: node.value,
};
},
});
declare function unionType<Result extends readonly unknown[]>(parsers: {
[K in keyof Result]: AnyExtractor<Result[K]>;
}): AnyExtractor<Result[number]>;
const myUnion = unionType([identifierExtractor, stringExtractor]);
| {
"end_byte": 1311,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/reverseMappedUnionInference.ts"
} |
TypeScript/tests/cases/compiler/import_unneeded-require-when-referenecing-aliased-type-throug-array.ts_0_262 | // @Filename: b.ts
declare module "ITest" {
interface Name {
name: string;
}
export = Name;
}
// @Filename: a.ts
//@module: amd
/// <reference path="b.ts" />
import ITest = require('ITest');
var testData: ITest[];
var p = testData[0].name;
| {
"end_byte": 262,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/import_unneeded-require-when-referenecing-aliased-type-throug-array.ts"
} |
TypeScript/tests/cases/compiler/declFileGenericType2.ts_0_1309 | // @declaration: true
declare module templa.mvc {
interface IModel {
}
}
declare module templa.mvc {
interface IController<ModelType extends templa.mvc.IModel> {
}
}
declare module templa.mvc {
class AbstractController<ModelType extends templa.mvc.IModel> implements mvc.IController<ModelType> {
}
}
declare module templa.mvc.composite {
interface ICompositeControllerModel extends mvc.IModel {
getControllers(): mvc.IController<mvc.IModel>[];
}
}
module templa.dom.mvc {
export interface IElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.IController<ModelType> {
}
}
// Module
module templa.dom.mvc {
export class AbstractElementController<ModelType extends templa.mvc.IModel> extends templa.mvc.AbstractController<ModelType> implements IElementController<ModelType> {
constructor() {
super();
}
}
}
// Module
module templa.dom.mvc.composite {
export class AbstractCompositeElementController<ModelType extends templa.mvc.composite.ICompositeControllerModel> extends templa.dom.mvc.AbstractElementController<ModelType> {
public _controllers: templa.mvc.IController<templa.mvc.IModel>[];
constructor() {
super();
this._controllers = [];
}
}
}
| {
"end_byte": 1309,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declFileGenericType2.ts"
} |
TypeScript/tests/cases/compiler/duplicateLabel1.ts_0_61 | // @allowUnusedLabels: true
target:
target:
while (true) {
} | {
"end_byte": 61,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/duplicateLabel1.ts"
} |
TypeScript/tests/cases/compiler/omitTypeTests01.ts_0_277 | // @declaration: true
interface Foo {
a: string;
b: number;
c: boolean;
}
export type Bar = Omit<Foo, "c">;
export type Baz = Omit<Foo, "b" | "c">;
export function getBarA(bar: Bar) {
return bar.a;
}
export function getBazA(baz: Baz) {
return baz.a;
}
| {
"end_byte": 277,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/omitTypeTests01.ts"
} |
TypeScript/tests/cases/compiler/enumWithNonLiteralStringInitializer.ts_0_342 | // @isolatedModules: true
// @noTypesAndSymbols: true
// @filename: ./helpers.ts
export const foo = 2;
export const bar = "bar";
// @filename: ./bad.ts
import { bar } from "./helpers";
enum A {
a = bar,
}
// @filename: ./good.ts
import { foo } from "./helpers";
enum A {
a = `${foo}`,
b = "" + 2,
c = 2 + "",
d = ("foo"),
}
| {
"end_byte": 342,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/enumWithNonLiteralStringInitializer.ts"
} |
TypeScript/tests/cases/compiler/isolatedModulesNoExternalModuleMultiple.ts_0_135 | // @isolatedModules: true
// @target: es6
// @filename: file1.ts
var x;
// @filename: file2.ts
var y;
// @filename: file3.ts
var z;
| {
"end_byte": 135,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/isolatedModulesNoExternalModuleMultiple.ts"
} |
TypeScript/tests/cases/compiler/collisionSuperAndLocalVarInProperty.ts_0_351 | var _super = 10; // No Error
class Foo {
public prop1 = {
doStuff: () => {
var _super = 10; // No error
}
}
public _super = 10; // No error
}
class b extends Foo {
public prop2 = {
doStuff: () => {
var _super = 10; // Should be error
}
}
public _super = 10; // No error
} | {
"end_byte": 351,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/collisionSuperAndLocalVarInProperty.ts"
} |
TypeScript/tests/cases/compiler/nodeResolution1.ts_0_132 | // @module: commonjs
// @moduleResolution: node
// @filename: a.ts
export var x = 1;
// @filename: b.ts
import y = require("./a"); | {
"end_byte": 132,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/nodeResolution1.ts"
} |
TypeScript/tests/cases/compiler/genericWithOpenTypeParameters1.ts_0_324 | class B<T> {
foo(x: T): T { return null; }
}
var x: B<number>;
x.foo(1); // no error
var f = <T>(x: B<T>) => { return x.foo(1); } // error
var f2 = <T>(x: B<T>) => { return x.foo<T>(1); } // error
var f3 = <T>(x: B<T>) => { return x.foo<number>(1); } // error
var f4 = (x: B<number>) => { return x.foo(1); } // no error
| {
"end_byte": 324,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericWithOpenTypeParameters1.ts"
} |
TypeScript/tests/cases/compiler/moduleWithNoValuesAsType.ts_0_161 | module A { }
var a: A; // error
module B {
interface I {}
}
var b: B; // error
module C {
module M {
interface I {}
}
}
var c: C; // error | {
"end_byte": 161,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/moduleWithNoValuesAsType.ts"
} |
TypeScript/tests/cases/compiler/declFileObjectLiteralWithAccessors.ts_0_258 | // @declaration: true
// @target: es5
function /*1*/makePoint(x: number) {
return {
b: 10,
get x() { return x; },
set x(a: number) { this.b = a; }
};
};
var /*4*/point = makePoint(2);
var /*2*/x = point.x;
point./*3*/x = 30; | {
"end_byte": 258,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declFileObjectLiteralWithAccessors.ts"
} |
TypeScript/tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts_3_326 | @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: noSuperInJSDocExtends.js
class Based { }
/** @extends {Based} */
class Derived {
constructor() {
this;
this.x = 10;
var that = this;
}
}
/** @extends {Based} */
class Derived2 {
constructor() {
super();
}
} | {
"end_byte": 326,
"start_byte": 3,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts"
} |
TypeScript/tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts_1_46638 | // Repro from #41223
/**
* This is a comment with dumb indentation for some auto-generated thing.
*/
export class SomeAutoGeneratedThing {} | {
"end_byte": 46638,
"start_byte": 1,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts"
} |
TypeScript/tests/cases/compiler/modulePreserveImportHelpers.ts_0_621 | // @module: preserve
// @target: es2022
// @importHelpers: true
// @Filename: /a.mts
declare var dec: any
@dec()
export class A {}
// @Filename: /b.cts
declare var dec: any
@dec()
class B {}
export {};
// @Filename: /c.ts
declare var dec: any
@dec()
export class C {}
// @filename: /package.json
{
"type": "module"
}
// @filename: /node_modules/tslib/package.json
{
"name": "tslib",
"main": "tslib.js",
"types": "tslib.d.ts"
}
// @filename: /node_modules/tslib/tslib.d.ts
export declare function __esDecorate(...args: any[]): any;
export declare function __runInitializers(...args: any[]): any;
| {
"end_byte": 621,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/modulePreserveImportHelpers.ts"
} |
TypeScript/tests/cases/compiler/unusedClassesinNamespace1.ts_0_97 | //@noUnusedLocals:true
//@noUnusedParameters:true
namespace Validation {
class c1 {
}
} | {
"end_byte": 97,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedClassesinNamespace1.ts"
} |
TypeScript/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts_0_213 | // @noImplicitReturns: true
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
try {
return get();
}
catch(e) {
log("in catch");
}
} | {
"end_byte": 213,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts"
} |
TypeScript/tests/cases/compiler/constEnumToStringWithComments.ts_0_464 | // @removeComments: false
const enum Foo {
X = 100,
Y = 0.5,
Z = 2.,
A = -1,
B = -1.5,
C = -1.
}
let x0 = Foo.X.toString();
let x1 = Foo["X"].toString();
let y0 = Foo.Y.toString();
let y1 = Foo["Y"].toString();
let z0 = Foo.Z.toString();
let z1 = Foo["Z"].toString();
let a0 = Foo.A.toString();
let a1 = Foo["A"].toString();
let b0 = Foo.B.toString();
let b1 = Foo["B"].toString();
let c0 = Foo.C.toString();
let c1 = Foo["C"].toString();
| {
"end_byte": 464,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/constEnumToStringWithComments.ts"
} |
TypeScript/tests/cases/compiler/argumentsReferenceInConstructor4_Js.ts_0_550 | // @declaration: true
// @allowJs: true
// @emitDeclarationOnly: true
// @filename: /a.js
class A {
/**
* Constructor
*
* @param {object} [foo={}]
*/
constructor(foo = {}) {
const key = "bar";
/**
* @type object
*/
this.foo = foo;
/**
* @type object
*/
const arguments = this.arguments;
/**
* @type object
*/
this.bar = arguments.bar;
/**
* @type object
*/
this.baz = arguments[key];
/**
* @type object
*/
this.options = arguments;
}
get arguments() {
return { bar: {} };
}
}
| {
"end_byte": 550,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/argumentsReferenceInConstructor4_Js.ts"
} |
TypeScript/tests/cases/compiler/declFileFunctions.ts_0_2280 | // @target: ES5
// @declaration: true
// @removeComments: false
// @module: commonjs
// @Filename: declFileFunctions_0.ts
/** This comment should appear for foo*/
export function foo() {
}
/** This is comment for function signature*/
export function fooWithParameters(/** this is comment about a*/a: string,
/** this is comment for b*/
b: number) {
var d = a;
}
export function fooWithRestParameters(a: string, ...rests: string[]) {
return a + rests.join("");
}
export function fooWithOverloads(a: string): string;
export function fooWithOverloads(a: number): number;
export function fooWithOverloads(a: any): any {
return a;
}
export function fooWithSingleOverload(a: string): string;
export function fooWithSingleOverload(a: any) {
return a;
}
export function fooWithTypePredicate(a: any): a is number {
return true;
}
export function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number {
return true;
}
export function fooWithTypeTypePredicateAndGeneric<T>(a: any): a is T {
return true;
}
export function fooWithTypeTypePredicateAndRestParam(a: any, ...rest): a is number {
return true;
}
/** This comment should appear for nonExportedFoo*/
function nonExportedFoo() {
}
/** This is comment for function signature*/
function nonExportedFooWithParameters(/** this is comment about a*/a: string,
/** this is comment for b*/
b: number) {
var d = a;
}
function nonExportedFooWithRestParameters(a: string, ...rests: string[]) {
return a + rests.join("");
}
function nonExportedFooWithOverloads(a: string): string;
function nonExportedFooWithOverloads(a: number): number;
function nonExportedFooWithOverloads(a: any): any {
return a;
}
// @Filename: declFileFunctions_1.ts
/** This comment should appear for foo*/
function globalfoo() {
}
/** This is comment for function signature*/
function globalfooWithParameters(/** this is comment about a*/a: string,
/** this is comment for b*/
b: number) {
var d = a;
}
function globalfooWithRestParameters(a: string, ...rests: string[]) {
return a + rests.join("");
}
function globalfooWithOverloads(a: string): string;
function globalfooWithOverloads(a: number): number;
function globalfooWithOverloads(a: any): any {
return a;
} | {
"end_byte": 2280,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/declFileFunctions.ts"
} |
TypeScript/tests/cases/compiler/unusedTypeParameters3.ts_0_195 | //@noUnusedLocals:true
//@noUnusedParameters:true
class greeter<typeparameter1, typeparameter2, typeparameter3> {
private x: typeparameter2;
public function1() {
this.x;
}
} | {
"end_byte": 195,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/unusedTypeParameters3.ts"
} |
TypeScript/tests/cases/compiler/aliasDoesNotDuplicateSignatures.ts_0_313 | // @filename: demo.d.ts
declare namespace demoNS {
function f(): void;
}
declare module 'demoModule' {
import alias = demoNS;
export = alias;
}
// @filename: user.ts
import { f } from 'demoModule';
// Assign an incorrect type here to see the type of 'f'.
let x1: string = demoNS.f;
let x2: string = f; | {
"end_byte": 313,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/aliasDoesNotDuplicateSignatures.ts"
} |
TypeScript/tests/cases/compiler/genericFunduleInModule2.ts_0_146 | module A {
export function B<T>(x: T) { return x; }
}
module A {
export module B {
export var x = 1;
}
}
var b: A.B;
A.B(1); | {
"end_byte": 146,
"start_byte": 0,
"url": "https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/genericFunduleInModule2.ts"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.