file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignmentWithExport.ts
TypeScript
// @allowJs: true // @checkJs: true // @Filename: a.js // @outDir: dist // this is a javascript file... export const Adapter = {}; Adapter.prop = {}; // comment this out, and it works Adapter.asyncMethod = function() {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeFromPrototypeAssignment.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: a.js // @strict: true // all references to _map, set, get, addon should be ok /** @constructor */ var Multimap = function() { this._map = {}; this._map this.set this.get this.addon }; Multimap.prototype = { set: function() { ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeFromPrototypeAssignment2.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: a.js // @strict: true // non top-level: // all references to _map, set, get, addon should be ok (function container() { /** @constructor */ var Multimap = function() { this._map = {}; this._map this.set this.get ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeFromPrototypeAssignment3.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: bug26885.js // @strict: true function Multimap3() { this._map = {}; }; Multimap3.prototype = { /** * @param {string} key * @returns {number} the value ok */ get(key) { return this._map[key + '']; } } /** @type {...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeFromPrototypeAssignment4.ts
TypeScript
// @allowJs: true // @checkJs: true // @emitDeclarationOnly: true // @declaration: true // @outDir: out // @Filename: a.js function Multimap4() { this._map = {}; }; Multimap4["prototype"] = { /** * @param {string} key * @returns {number} the value ok */ get(key) { return this._map[key + '']; } };...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardEnums.ts
TypeScript
enum E {} enum V {} let x: number|string|E|V; if (typeof x === "number") { x; // number|E|V } else { x; // string } if (typeof x !== "number") { x; // string } else { x; // number|E|V }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardFunction.ts
TypeScript
class A { propA: number; } class B { propB: number; } class C extends A { propC: number; } declare function isA(p1: any): p1 is A; declare function isB(p1: any): p1 is B; declare function isC(p1: any): p1 is C; declare function retC(): C; var a: A; var b: B; // Basic if (isC(a)) { a.propC; } // ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardFunctionGenerics.ts
TypeScript
class A { propA: number; } class B { propB: number; } class C extends A { propC: number; } declare function isB(p1): p1 is B; declare function isC(p1): p1 is C; declare function retC(x): C; declare function funA<T>(p1: (p1) => T): T; declare function funB<T>(p1: (p1) => T, p2: any): p2 is T; declare f...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardFunctionOfFormThis.ts
TypeScript
// @declaration: true class RoyalGuard { isLeader(): this is LeadGuard { return this instanceof LeadGuard; } isFollower(): this is FollowerGuard { return this instanceof FollowerGuard; } } class LeadGuard extends RoyalGuard { lead(): void {}; } class FollowerGuard extends RoyalGuar...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardFunctionOfFormThisErrors.ts
TypeScript
// @declaration: true class RoyalGuard { isLeader(): this is LeadGuard { return this instanceof LeadGuard; } isFollower(): this is FollowerGuard { return this instanceof FollowerGuard; } } class LeadGuard extends RoyalGuard { lead(): void {}; } class FollowerGuard extends RoyalGuar...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardInClass.ts
TypeScript
let x: string | number; if (typeof x === "string") { let n = class { constructor() { let y: string = x; } } } else { let m = class { constructor() { let y: number = x; } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardIntersectionTypes.ts
TypeScript
// @strictNullChecks: true interface X { x: string; } interface Y { y: string; } interface Z { z: string; } declare function isX(obj: any): obj is X; declare function isY(obj: any): obj is Y; declare function isZ(obj: any): obj is Z; function f1(obj: Object) { if (isX(obj) || isY(obj) || isZ(obj)) ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardNarrowsPrimitiveIntersection.ts
TypeScript
type Tag = {__tag: any}; declare function isNonBlank(value: string) : value is (string & Tag); declare function doThis(value: string & Tag): void; declare function doThat(value: string) : void; let value: string; if (isNonBlank(value)) { doThis(value); } else { doThat(value); } const enum Tag2 {} declare func...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardNarrowsToLiteralType.ts
TypeScript
declare function isFoo(value: string) : value is "foo"; declare function doThis(value: "foo"): void; declare function doThat(value: string) : void; let value: string; if (isFoo(value)) { doThis(value); } else { doThat(value); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardNarrowsToLiteralTypeUnion.ts
TypeScript
declare function isFoo(value: string) : value is ("foo" | "bar"); declare function doThis(value: "foo" | "bar"): void; declare function doThat(value: string) : void; let value: string; if (isFoo(value)) { doThis(value); } else { doThat(value); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardNesting.ts
TypeScript
let strOrBool: string|boolean; if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'string') { let label: string = (typeof strOrBool === 'string') ? strOrBool : "string"; let bool: boolean = (typeof strOrBool === 'boolean') ? strOrBool : false; let label2: string = (typeof strOrBool !== 'boole...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormExpr1AndExpr2.ts
TypeScript
var str: string; var bool: boolean; var num: number; var strOrNum: string | number; var strOrNumOrBool: string | number | boolean; var numOrBool: number | boolean; class C { private p; } var c: C; var cOrBool: C| boolean; var strOrNumOrBoolOrC: string | number | boolean | C; // A type guard of the form expr1 && expr2 ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormExpr1OrExpr2.ts
TypeScript
var str: string; var bool: boolean; var num: number; var strOrNum: string | number; var strOrNumOrBool: string | number | boolean; var numOrBool: number | boolean; class C { private p; } var c: C; var cOrBool: C| boolean; var strOrNumOrBoolOrC: string | number | boolean | C; // A type guard of the form expr1 || expr2 ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormFunctionEquality.ts
TypeScript
declare function isString1(a: number, b: Object): b is string; declare function isString2(a: Object): a is string; switch (isString1(0, "")) { case isString2(""): default: } var x = isString1(0, "") === isString2(""); function isString3(a: number, b: number, c: Object): c is string { return isString1(0,...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormInstanceOf.ts
TypeScript
// A type guard of the form x instanceof C, where C is of a subtype of the global type 'Function' // and C has a property named 'prototype' // - when true, narrows the type of x to the type of the 'prototype' property in C provided // it is a subtype of the type of x, or // - when false, has no effect on the typ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormInstanceOfOnInterface.ts
TypeScript
// A type guard of the form x instanceof C, where C is of a subtype of the global type 'Function' // and C has a property named 'prototype' // - when true, narrows the type of x to the type of the 'prototype' property in C provided // it is a subtype of the type of x, or // - when false, has no effect on the typ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormIsType.ts
TypeScript
class C1 { p1: string; } class C2 { p2: number; } class D1 extends C1 { p3: number; } var str: string; var num: number; var strOrNum: string | number; function isC1(x: any): x is C1 { return true; } function isC2(x: any): x is C2 { return true; } function isD1(x: any): x is D1 { return true;...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormIsTypeOnInterfaces.ts
TypeScript
interface C1 { (): C1; prototype: C1; p1: string; } interface C2 { (): C2; prototype: C2; p2: number; } interface D1 extends C1 { prototype: D1; p3: number; } var str: string; var num: number; var strOrNum: string | number; function isC1(x: any): x is C1 { return true; } function...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormNotExpr.ts
TypeScript
var str: string; var bool: boolean; var num: number; var strOrNum: string | number; var strOrNumOrBool: string | number | boolean; var numOrBool: number | boolean; // A type guard of the form !expr // - when true, narrows the type of x by expr when false, or // - when false, narrows the type of x by expr when true. /...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfBoolean.ts
TypeScript
class C { private p: string }; var str: string; var bool: boolean; var num: number; var strOrNum: string | number; var strOrBool: string | boolean; var numOrBool: number | boolean var strOrNumOrBool: string | number | boolean; var strOrC: string | C; var numOrC: number | C; var boolOrC: boolean | C; var c: C; // A ty...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts
TypeScript
class C { private p: string }; var strOrNum: string | number; var strOrBool: string | boolean; var numOrBool: number | boolean var strOrC: string | C; // typeof x == s has not effect on typeguard if (typeof strOrNum == "string") { var r1 = strOrNum; // string | number } else { var r1 = strOrNum; // string | n...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfFunction.ts
TypeScript
function f1(x: any) { if (typeof x === "function") { x; // any } } function f2(x: unknown) { if (typeof x === "function") { x; // Function } } function f3(x: {}) { if (typeof x === "function") { x; // Function } } function f4<T>(x: T) { if (typeof x === "functi...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfIsOrderIndependent.ts
TypeScript
var strOrNum: string | number; var strOrBool: string | boolean; var strOrFunc: string | (() => void); var numOrBool: number | boolean var str: string; var num: number; var bool: boolean; var func: () => void; if ("string" === typeof strOrNum) { str = strOrNum; } else { num = strOrNum; } if ("function" === type...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts
TypeScript
class C { private p: string }; var strOrNum: string | number; var strOrBool: string | boolean; var numOrBool: number | boolean var strOrC: string | C; // typeof x != s has not effect on typeguard if (typeof strOrNum != "string") { var r1 = strOrNum; // string | number } else { var r1 = strOrNum; // string | n...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfNumber.ts
TypeScript
class C { private p: string }; var str: string; var bool: boolean; var num: number; var strOrNum: string | number; var strOrBool: string | boolean; var numOrBool: number | boolean var strOrNumOrBool: string | number | boolean; var strOrC: string | C; var numOrC: number | C; var boolOrC: boolean | C; var c: C; // A ty...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfOther.ts
TypeScript
class C { private p: string }; var str: string; var bool: boolean; var num: number; var strOrNum: string | number; var strOrBool: string | boolean; var numOrBool: number | boolean var strOrNumOrBool: string | number | boolean; var strOrC: string | C; var numOrC: number | C; var boolOrC: boolean | C; var emptyObj: {}; ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfPrimitiveSubtype.ts
TypeScript
let a: {}; let b: {toString(): string}; if (typeof a === "number") { let c: number = a; } if (typeof a === "string") { let c: string = a; } if (typeof a === "boolean") { let c: boolean = a; } if (typeof b === "number") { let c: number = b; } if (typeof b === "string") { let c: string = b; } if (typ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFormTypeOfString.ts
TypeScript
class C { private p: string }; var str: string; var bool: boolean; var num: number; var strOrNum: string | number; var strOrBool: string | boolean; var numOrBool: number | boolean var strOrNumOrBool: string | number | boolean; var strOrC: string | C; var numOrC: number | C; var boolOrC: boolean | C; var c: C; // A ty...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardOfFromPropNameInUnionType.ts
TypeScript
class A { a: string; } class B { b: number; } class C { b: Object; } class D { a: Date; } function namedClasses(x: A | B) { if ("a" in x) { x.a = "1"; } else { x.b = 1; } } function multipleClasses(x: A | B | C | D) { if ("a" in x) { let y: string | Date = x.a; } else { ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardRedundancy.ts
TypeScript
var x: string|number; var r1 = typeof x === "string" && typeof x === "string" ? x.substr : x.toFixed; var r2 = !(typeof x === "string" && typeof x === "string") ? x.toFixed : x.substr; var r3 = typeof x === "string" || typeof x === "string" ? x.substr : x.toFixed; var r4 = !(typeof x === "string" || typeof x === "s...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardTautologicalConsistiency.ts
TypeScript
let stringOrNumber: string | number; if (typeof stringOrNumber === "number") { if (typeof stringOrNumber !== "number") { stringOrNumber; } } if (typeof stringOrNumber === "number" && typeof stringOrNumber !== "number") { stringOrNumber; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardTypeOfUndefined.ts
TypeScript
// undefined type guard adds no new type information function test1(a: any) { if (typeof a !== "undefined") { if (typeof a === "boolean") { a; } else { a; } } else { a; } } function test2(a: any) { if (typeof a === "undefined") { ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsAsAssertions.ts
TypeScript
// @strictNullChecks: true // Repro from #8513 let cond: boolean; export type Optional<a> = Some<a> | None; export interface None { readonly none: string; } export interface Some<a> { readonly some: a; } export const none : None = { none: '' }; export function isSome<a>(value: Optional<a>): value is Some<a> { ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsDefeat.ts
TypeScript
// Also note that it is possible to defeat a type guard by calling a function that changes the // type of the guarded variable. function foo(x: number | string) { function f() { x = 10; } if (typeof x === "string") { f(); return x.length; // string } else { return x+...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInClassAccessors.ts
TypeScript
//@target: es5 // Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // variables in global var num: number; var strOrNum: string | number; var var1: string | number; class ClassWithAccessors { // Inside public accessor getter ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInClassMethods.ts
TypeScript
// Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // variables in global var num: number; var var1: string | number; class C1 { constructor(param: string | number) { // global vars in function declaration num = t...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInConditionalExpression.ts
TypeScript
// In the true expression of a conditional expression, // the type of a variable or parameter is narrowed by any type guard in the condition when true, // provided the true expression contains no assignments to the variable or parameter. // In the false expression of a conditional expression, // the type of a variab...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInDoStatement.ts
TypeScript
let cond: boolean; function a(x: string | number | boolean) { x = true; do { x; // boolean | string x = undefined; } while (typeof x === "string") x; // number | boolean } function b(x: string | number | boolean) { x = true; do { x; // boolean | string if (cond) c...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInExternalModule.ts
TypeScript
//@module: commonjs // Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // local variable in external module var num: number; var var1: string | number; if (typeof var1 === "string") { num = var1.length; // string } else { num...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInForStatement.ts
TypeScript
let cond: boolean; function a(x: string | number) { for (x = undefined; typeof x !== "number"; x = undefined) { x; // string } x; // number } function b(x: string | number) { for (x = undefined; typeof x !== "number"; x = undefined) { x; // string if (cond) continue; } x;...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInFunction.ts
TypeScript
// Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // variables in global var num: number; var var1: string | number; // Inside function declaration function f(param: string | number) { // global vars in function declaration ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInFunctionAndModuleBlock.ts
TypeScript
// typeguards are scoped in function/module block function foo(x: number | string | boolean) { return typeof x === "string" ? x : function f() { var b = x; // number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toStrin...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInGlobal.ts
TypeScript
// Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // variables in global var num: number; var var1: string | number; if (typeof var1 === "string") { num = var1.length; // string } else { num = var1; // number }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInIfStatement.ts
TypeScript
// In the true branch statement of an 'if' statement, // the type of a variable or parameter is narrowed by any type guard in the 'if' condition when true. // In the false branch statement of an 'if' statement, // the type of a variable or parameter is narrowed by any type guard in the 'if' condition when false. func...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInModule.ts
TypeScript
// Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // variables in global var num: number; var strOrNum: string | number; var var1: string | number; // Inside module module m1 { // global vars in function declaration num = ty...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInProperties.ts
TypeScript
//@target: es5 // Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. var num: number; var strOrNum: string | number; class C1 { private pp1: string | number; pp2: string | number; // Inside public accessor getter get pp...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInRightOperandOfAndAndOperator.ts
TypeScript
// In the right operand of a && operation, // the type of a variable or parameter is narrowed by any type guard in the left operand when true. function foo(x: number | string) { return typeof x === "string" && x.length === 10; // string } function foo2(x: number | string) { // modify x in right hand operand ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInRightOperandOfOrOrOperator.ts
TypeScript
// In the right operand of a || operation, // the type of a variable or parameter is narrowed by any type guard in the left operand when false, // provided the right operand contains no assignments to the variable or parameter. function foo(x: number | string) { return typeof x !== "string" || x.length === 10; //...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsInWhileStatement.ts
TypeScript
let cond: boolean; function a(x: string | number) { while (typeof x === "string") { x; // string x = undefined; } x; // number } function b(x: string | number) { while (typeof x === "string") { if (cond) continue; x; // string x = undefined; } x; // number...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsNestedAssignments.ts
TypeScript
// @strictNullChecks: true class Foo { x: string; } declare function getFooOrNull(): Foo | null; declare function getStringOrNumberOrNull(): string | number | null; function f1() { let foo: Foo | null; if ((foo = getFooOrNull()) !== null) { foo; // Foo } } function f2() { let foo1: Foo ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsObjectMethods.ts
TypeScript
//@target: es5 // Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // variables in global var num: number; var strOrNum: string | number; var var1: string | number; var obj1 = { // Inside method method(param: string | number)...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsOnClassProperty.ts
TypeScript
// Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // Note that the class's property must be copied to a local variable for // the type guard to have an effect class D { data: string | string[]; getData() { var data ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsTypeParameters.ts
TypeScript
// @strictNullChecks: true // Type guards involving type parameters produce intersection types class C { prop: string; } function f1<T>(x: T) { if (x instanceof C) { let v1: T = x; let v2: C = x; x.prop; } } function f2<T>(x: T) { if (typeof x === "string") { let v1: ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsWithAny.ts
TypeScript
var x: any = { p: 0 }; if (x instanceof Object) { x.p; // No error, type any unaffected by instanceof type guard } else { x.p; // No error, type any unaffected by instanceof type guard } if (typeof x === "string") { x.p; // Error, type any narrowed by primitive type check } else { x.p; // No error, ty...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsWithInstanceOf.ts
TypeScript
// @strictNullChecks: true interface I { global: string; } var result!: I; var result2!: I; if (!(result instanceof RegExp)) { result = result2; } else if (!result.global) { } // Repro from #31155 interface OnChanges { onChanges(changes: Record<string, unknown>): void } interface Validator { validate()...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsWithInstanceOfByConstructorSignature.ts
TypeScript
interface AConstructor { new (): A; } interface A { foo: string; } declare var A: AConstructor; var obj1: A | string; if (obj1 instanceof A) { // narrowed to A. obj1.foo; obj1.bar; } var obj2: any; if (obj2 instanceof A) { obj2.foo; obj2.bar; } // a construct signature with generics interface...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeGuardsWithInstanceOfBySymbolHasInstance.ts
TypeScript
// @lib: esnext interface AConstructor { new (): A; [Symbol.hasInstance](value: unknown): value is A; } interface A { foo: string; } declare var A: AConstructor; var obj1: A | string; if (obj1 instanceof A) { // narrowed to A. obj1.foo; obj1.bar; } var obj2: any; if (obj2 instanceof A) { obj2...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeInferenceWithTupleType.ts
TypeScript
function combine<T, U>(x: T, y: U): [T, U] { return [x, y]; } var combineResult = combine("string", 10); var combineEle1 = combineResult[0]; // string var combineEle2 = combineResult[1]; // number function zip<T, U>(array1: T[], array2: U[]): [[T, U]] { if (array1.length != array2.length) { return [[u...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeLookupInIIFE.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @Filename: a.js // #22973 var ns = (function() {})(); /** @type {ns.NotFound} */ var crash;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisGeneral.ts
TypeScript
// @target: esnext // @useDefineForClassFields: false class MyTestClass { private canary: number; static staticCanary: number; constructor() { //type of 'this' in constructor body is the class instance type var p = this.canary; var p: number; this.canary = 3; } //ty...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInAccessor.ts
TypeScript
class C { get x() { var r = this; // C return 1; } static get y() { var r2 = this; // typeof C return 1; } } class D<T> { a: T; get x() { var r = this; // D<T> return 1; } static get y() { var r2 = this; // typeof D retur...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInConstructorParamList.ts
TypeScript
//type of 'this' in constructor param list is the class instance type (error) class ErrClass { // Should be an error constructor(f = this) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInFunctionExpression.ts
TypeScript
// type of 'this' in FunctionExpression is Any function fn() { var p = this; var p: any; } var t = function () { var p = this; var p: any; } var t2 = function f() { var x = this; var x: any; } class C { x = function () { var q: any; var q = this; } y = function ff...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInInstanceMember.ts
TypeScript
class C { x = this; foo() { return this; } constructor(x: number) { var t = this; t.x; t.y; t.z; var r = t.foo(); } get y() { return this; } } var c: C; // all ok var r = c.x; var ra = c.x.x.x; var r2 = c.y; var r3 = c.foo(); var rs =...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInInstanceMember2.ts
TypeScript
class C<T> { x = this; foo() { return this; } constructor(x: T) { var t = this; t.x; t.y; t.z; var r = t.foo(); } get y() { return this; } z: T; } var c: C<string>; // all ok var r = c.x; var ra = c.x.x.x; var r2 = c.y; var r3 = ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInMemberFunctions.ts
TypeScript
class C { foo() { var r = this; } static bar() { var r2 = this; } } class D<T> { x: T; foo() { var r = this; } static bar() { var r2 = this; } } class E<T extends Date> { x: T; foo() { var r = this; } static bar() { ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers.ts
TypeScript
class C { constructor(x: number) { } static foo: number; static bar() { // type of this is the constructor function type var t = this; return this; } } var t = C.bar(); // all ok var r2 = t.foo + 1; var r3 = t.bar(); var r4 = new t(1); class C2<T> { static test: number; ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers10.ts
TypeScript
// @target: esnext, es2022, es6, es5 // @experimentalDecorators: true // @useDefineForClassFields: false declare const foo: any; @foo class C { static a = 1; static b = this.a + 1; } @foo class D extends C { static c = 2; static d = this.c + 1; static e = super.a + this.c + 1; static f = () =...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers11.ts
TypeScript
// @target: esnext, es2022, es6, es5 // @experimentalDecorators: true // @useDefineForClassFields: true declare const foo: any; @foo class C { static a = 1; static b = this.a + 1; } @foo class D extends C { static c = 2; static d = this.c + 1; static e = super.a + this.c + 1; static f = () =>...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers2.ts
TypeScript
class C { static foo = this; // ok } class C2<T> { static foo = this; // ok }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers3.ts
TypeScript
// @target: esnext, es2022, es6, es5 // @useDefineForClassFields: false class C { static a = 1; static b = this.a + 1; } class D extends C { static c = 2; static d = this.c + 1; static e = super.a + this.c + 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers4.ts
TypeScript
// @target: esnext, es2022, es6, es5 // @useDefineForClassFields: true class C { static a = 1; static b = this.a + 1; } class D extends C { static c = 2; static d = this.c + 1; static e = super.a + this.c + 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers5.ts
TypeScript
// @target: esnext, es2022, es6, es5 class C { static create = () => new this("yep") constructor (private foo: string) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers6.ts
TypeScript
class C { static f = 1 } class D extends C { static c = super(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers7.ts
TypeScript
// @target: esnext, es2022, es6, es5 class C { static a = 1; static b = this.a + 1; } class D extends C { static c = 2; static d = this.c + 1; static e = 1 + (super.a) + (this.c + 1) + 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers8.ts
TypeScript
// @target: esnext, es2022, es6, es5 class C { static f = 1; static arrowFunctionBoundary = () => this.f + 1; static functionExprBoundary = function () { return this.f + 2 }; static classExprBoundary = class { a = this.f + 3 }; static functionAndClassDeclBoundary = (() => { function foo () ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInStaticMembers9.ts
TypeScript
// @target: esnext, es2022, es6, es5 class C { static f = 1 } class D extends C { static arrowFunctionBoundary = () => super.f + 1; static functionExprBoundary = function () { return super.f + 2 }; static classExprBoundary = class { a = super.f + 3 }; static functionAndClassDeclBoundary = (() => {...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOfThisInstanceMemberNarrowedWithLoopAntecedent.ts
TypeScript
// #31995 type State = { type: "numberVariant"; data: number; } | { type: "stringVariant"; data: string; }; class SomeClass { state!: State; method() { while (0) { } this.state.data; if (this.state.type === "stringVariant") { const s: string = this.state.data...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOnlyMerge1.ts
TypeScript
// @Filename: a.ts interface A {} export type { A }; // @Filename: b.ts import { A } from "./a"; const A = 0; export { A }; // @Filename: c.ts import { A } from "./b"; A;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOnlyMerge2.ts
TypeScript
// @Filename: a.ts const A = {} export { A }; // @Filename: b.ts import { A } from "./a"; type A = any; export type { A }; // @Filename: c.ts import { A } from "./b"; namespace A {} export { A }; // @Filename: d.ts import { A } from "./c"; A;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeOnlyMerge3.ts
TypeScript
// @Filename: a.ts function A() {} export type { A }; // @Filename: b.ts import { A } from "./a"; namespace A { export const displayName = "A"; } export { A }; // @Filename: c.ts import { A } from "./b"; A; A.displayName; A();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAsBaseType.ts
TypeScript
// type parameters cannot be used as base types // these are all errors class C<T> extends T { } class C2<T, U> extends U { } interface I<T> extends T { } interface I2<T, U> extends U { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAsTypeArgument.ts
TypeScript
// These are all errors because type parameters cannot reference other type parameters from the same list function foo<T, U>(x: T, y: U) { foo<U, U>(y, y); return new C<U,T>(); } class C<T, U> { x: T; } interface I<T, U> { x: C<U, T>; } //function foo<T, U extends T>(x: T, y: U) { // foo<U, U>(y,...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAsTypeParameterConstraint.ts
TypeScript
// using a type parameter as a constraint for a type parameter is valid // no errors expected except illegal constraints function foo<T, U extends T>(x: T, y: U): U { return y; } var r = foo(1, 2); var r = foo({}, 1); interface A { foo: string; } interface B extends A { bar: number; } var a: A; var b: B; va...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAsTypeParameterConstraint2.ts
TypeScript
// using a type parameter as a constraint for a type parameter is invalid // these should be errors unless otherwise noted function foo<T, U extends T>(x: T, y: U): U { return y; } // this is now an error foo(1, ''); foo(1, {}); interface NumberVariant extends Number { x: number; } var n: NumberVariant; var r3 =...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAsTypeParameterConstraintTransitively.ts
TypeScript
// using a type parameter as a constraint for a type parameter is valid // no errors expected interface A { foo: number } interface B extends A { bar: string; } interface C extends B { baz: boolean; } var a: A; var b: B; var c: C; function foo<T, U, V>(x: T, y: U, z: V): V { return z; } //function foo<T, U extends T,...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAsTypeParameterConstraintTransitively2.ts
TypeScript
// using a type parameter as a constraint for a type parameter is invalid // these should be errors at the type parameter constraint declarations, and have no downstream errors interface A { foo: number } interface B extends A { bar: string; } interface C extends B { baz: boolean; } var a: A; var b: B; var c: C; func...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAssignability.ts
TypeScript
// type parameters are not assignable to one another unless directly or indirectly constrained to one another function foo<T, U>(t: T, u: U) { t = u; // error u = t; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAssignability2.ts
TypeScript
// type parameters are not assignable to one another unless directly or indirectly constrained to one another function foo<T, U extends T>(t: T, u: U) { t = u; // error u = t; // ok } function foo2<T extends U, U>(t: T, u: U) { t = u; // error u = t; // ok } function foo3<T extends U, U extends V, V>...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterAssignability3.ts
TypeScript
// type parameters are not assignable to one another unless directly or indirectly constrained to one another class Foo { foo: string; } function foo<T extends Foo, U extends Foo>(t: T, u: U) { var a: T; var b: U; t = a; // ok a = t; // ok b = u; // ok u = b; // ok t = u; // error u ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterConstModifiersReverseMappedTypes.ts
TypeScript
// @strict: true // @noEmit: true declare function test1<const T>(obj: { [K in keyof T]: T[K]; }): [T, typeof obj]; const result1 = test1({ prop: "foo", nested: { nestedProp: "bar", }, }); declare function test2<const T>(obj: { readonly [K in keyof T]: T[K]; }): [T, typeof obj]; const result2 = test2(...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterConstModifiersWithIntersection.ts
TypeScript
// @strict: true // @noEmit: true // https://github.com/microsoft/TypeScript/issues/55778 interface Config<T1 extends { type: string }> { useIt: T1; } declare function test< T1 extends { type: string }, const TConfig extends Config<T1>, >(config: { produceThing: T1 } & TConfig): TConfig; const result = test({...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterDirectlyConstrainedToItself.ts
TypeScript
// all of the below should be errors class C<T extends T> { } class C2<T, U extends U> { } interface I<T extends T> { } interface I2<T, U extends U> { } function f<T extends T>() { } function f2<T, U extends U>() { } var a: { <T extends T>(): void; <T, U extends U>(): void; } var b = <T extends T>() => {...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterExtendsUnionConstraintDistributed.ts
TypeScript
type A = 1 | 2; function f<T extends A>(a: T): A & T { return a; } // Shouldn't error type B = 2 | 3; function f2<T extends A, U extends B>(ab: T & U): (A | B) & T & U { return ab; } // Also shouldn't error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/typeParameterIndirectlyConstrainedToItself.ts
TypeScript
class C<U extends T, T extends U> { } class C2<T extends U, U extends V, V extends T> { } interface I<U extends T, T extends U> { } interface I2<T extends U, U extends V, V extends T> { } function f<U extends T, T extends U>() { } function f2<T extends U, U extends V, V extends T>() { } var a: { <U extends T, T ...
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University