Merge branch 'master' into limit-recursive-structured-type-resolution

This commit is contained in:
Nathan Shively-Sanders
2017-12-22 14:41:58 -08:00
722 changed files with 180743 additions and 84881 deletions
+5
View File
@@ -0,0 +1,5 @@
// TODO: remove lib hack when https://github.com/Microsoft/TypeScript/issues/20454 is fixed
type Fn<T extends object> = <U extends T>(subj: U) => U
function doStuff<T extends object, T1 extends T>(a: Array<Fn<T>>, b: Array<Fn<T1>>) {
b.concat(a);
}
+34
View File
@@ -0,0 +1,34 @@
// @lib: es2015
// Tests fix for #20432, ensures Array.from accepts all valid inputs
// Also tests for #19682
interface A {
a: string;
}
interface B {
b: string;
}
const inputA: A[] = [];
const inputB: B[] = [];
const inputALike: ArrayLike<A> = { length: 0 };
const inputARand = getEither(inputA, inputALike);
const result1: A[] = Array.from(inputA);
const result2: A[] = Array.from(inputA.values());
const result3: B[] = Array.from(inputA.values()); // expect error
const result4: A[] = Array.from(inputB, ({ b }): A => ({ a: b }));
const result5: A[] = Array.from(inputALike);
const result6: B[] = Array.from(inputALike); // expect error
const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a }));
const result8: A[] = Array.from(inputARand);
const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
// if this is written inline, the compiler seems to infer
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,
// even when the type is written as : Iterable<T>|ArrayLike<T>
function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) {
return Math.random() > 0.5 ? in1 : in2;
}
@@ -0,0 +1,17 @@
// https://github.com/Microsoft/TypeScript/issues/16861
class BaseType<T> {
bar: T
}
class NextType<C extends { someProp: any }, T = C['someProp']> extends BaseType<T> {
baz: string;
}
class Foo extends NextType<Foo> {
someProp: {
test: true
}
}
const foo = new Foo();
foo.bar.test
@@ -0,0 +1,5 @@
class A {
private x: number;
}
class B implements A {}
+2
View File
@@ -20,6 +20,7 @@ const enum Enum1 {
N = E << 1,
O = E >> B,
P = E >> 1,
PQ = E ** 2,
Q = -D,
R = C & 5,
S = 5 & C,
@@ -127,6 +128,7 @@ function foo(x: Enum1) {
case Enum1.N:
case Enum1.O:
case Enum1.P:
case Enum1.PQ:
case Enum1.Q:
case Enum1.R:
case Enum1.S:
@@ -0,0 +1,96 @@
// @strict: true
interface X {
type: 'x';
value: string;
method(): void;
}
interface Y {
type: 'y';
value: 'none' | 'done';
method(): void;
}
function foo(bar: X | Y) { }
foo({
type: 'y',
value: 'done',
method() {
this;
this.type;
this.value;
}
});
interface X2 {
type1: 'x';
value: string;
method(): void;
}
interface Y2 {
type2: 'y';
value: 'none' | 'done';
method(): void;
}
function foo2(bar: X2 | Y2) { }
foo2({
type2: 'y',
value: 'done',
method() {
this;
this.value;
}
});
interface X3 {
type: 'x';
value: 1 | 2 | 3;
xtra: number;
}
interface Y3 {
type: 'y';
value: 11 | 12 | 13;
ytra: number;
}
let xy: X3 | Y3 = {
type: 'y',
value: 11,
ytra: 12
};
xy;
interface LikeA {
x: 'x';
y: 'y';
value: string;
method(): void;
}
interface LikeB {
x: 'xx';
y: 'yy';
value: number;
method(): void;
}
let xyz: LikeA | LikeB = {
x: 'x',
y: 'y',
value: "foo",
method() {
this;
this.x;
this.y;
this.value;
}
};
xyz;
@@ -0,0 +1,8 @@
// @declaration: true
// @filename: thingB.ts
export interface ThingB { }
// @filename: things.ts
export * from "./thingB";
// @filename: index.ts
import * as things from "./things";
export const thing2 = (param: things.ThingB) => null;
@@ -0,0 +1,22 @@
// @strict: true
// Repro from #20196
type A = {
a: (x: number) => string
};
type B = {
a: (x: boolean) => string
};
function call0(p: A | B) {
p.a("s"); // Error
}
function callN<T extends A | B>(p: T) {
p.a("s"); // Error
var a: T["a"] = p.a;
a(""); // Error
a("", "", "", ""); // Error
}
@@ -0,0 +1,5 @@
// @target: esnext
function* f(): Iterator<number> {
return invalid;
}
@@ -0,0 +1,11 @@
declare class Foo {
x: string;
}
declare class Bar {
y: string;
}
type Wrapper = Foo & Bar;
class Baz implements Wrapper {
x: number;
y: string;
}
@@ -0,0 +1,21 @@
// @declaration: true
// @filename: internal.ts
namespace My.Internal {
export function getThing(): void {}
export const enum WhichThing {
A, B, C
}
}
// @filename: usage.ts
/// <reference path="./internal.ts" />
namespace SomeOther.Thing {
import Internal = My.Internal;
export class Foo {
private _which: Internal.WhichThing;
constructor() {
Internal.getThing();
Internal.WhichThing.A ? "foo" : "bar";
}
}
}
@@ -0,0 +1,97 @@
class A { a: string; }
class B { b: string; }
function negativeClassesTest(x: A | B) {
if ("a" in x) {
x.b = "1";
} else {
x.a = "1";
}
}
function positiveClassesTest(x: A | B) {
if ("a" in x) {
x.b = "1";
} else {
x.a = "1";
}
}
class AWithOptionalProp { a?: string; }
class BWithOptionalProp { b?: string; }
function positiveTestClassesWithOptionalProperties(x: AWithOptionalProp | BWithOptionalProp) {
if ("a" in x) {
x.a = "1";
} else {
x.b = "1";
}
}
class AWithMethod {
a(): string { return ""; }
}
class BWithMethod {
b(): string { return ""; }
}
function negativeTestClassesWithMembers(x: AWithMethod | BWithMethod) {
if ("a" in x) {
x.a();
x.b();
} else {
}
}
function negativeTestClassesWithMemberMissingInBothClasses(x: AWithMethod | BWithMethod) {
if ("c" in x) {
x.a();
x.b();
} else {
x.a();
x.b();
}
}
class C { a: string; }
class D { a: string; }
function negativeMultipleClassesTest(x: A | B | C | D) {
if ("a" in x) {
x.b = "1";
} else {
x.a = "1";
}
}
class ClassWithUnionProp { prop: A | B }
function negativePropTest(x: ClassWithUnionProp) {
if ("a" in x.prop) {
let y: string = x.prop.b;
} else {
let z: string = x.prop.a;
}
}
class NegativeClassTest {
protected prop: A | B;
inThis() {
if ("a" in this.prop) {
let z: number = this.prop.b;
} else {
let y: string = this.prop.a;
}
}
}
class UnreachableCodeDetection {
a: string;
inThis() {
if ("a" in this) {
} else {
let y = this.a;
}
}
}
@@ -0,0 +1,11 @@
declare function get<U, Y extends keyof U>(x: U, y: Y): U[Y];
declare function find<T, K extends keyof T>(o: T[K]): [T, K];
function impl<A, B extends keyof A>(a: A, b: B) {
const item = get(a, b);
return find(item);
}
const o = {x: 42};
const r = impl(o, "x");
r[0][r[1]] = o[r[1]];
+7 -1
View File
@@ -8,6 +8,12 @@ declare class A<T> { x: T; }
// @Filename: /b.js
class B extends A {}
new B().x;
/** @augments A */
class C { }
class C extends A { }
new C().x;
/** @augments A<number, number, number> */
class D extends A {}
new D().x;
@@ -0,0 +1,17 @@
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @outDir: ./built
// @filename: somelib.d.ts
export declare class Foo<T> {
prop: T;
}
// @filename: index.js
import {Foo} from "./somelib";
class MyFoo extends Foo {
constructor() {
super();
this.prop.alpha = 12;
}
}
@@ -0,0 +1,20 @@
// @jsx: react
// @libFiles: lib.d.ts,react.d.ts
// @skipLibCheck: true
// @allowSyntheticDefaultImports: true
import React from "react";
type InfoProps =
| { status: "hidden" }
| { status: "visible"; content: string };
const Info = (props: InfoProps) =>
props.status === "hidden"
? <noscript />
: <div>{props.content}</div>;
const a = <Info status="hidden" />;
const b = <Info status="visible" content="hello world" />;
declare const infoProps: InfoProps;
const c = <Info {...infoProps} />;
@@ -0,0 +1 @@
const x: { type: string } & { type: "string" } = { type: "string" };
@@ -0,0 +1,5 @@
interface A { a: A }
declare let a: A;
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
declare function foo<T>(deep: Deep<T>): T;
const out = foo(a);
@@ -0,0 +1,18 @@
// https://github.com/Microsoft/TypeScript/issues/19632
declare function direct<A extends string>(a: A | A[]): Record<A, string>
declare function nested<A extends string>(a: { fields: A }): Record<A, string>
declare function nestedUnion<A extends string>(a: { fields: A | A[] }): Record<A, string>
const directUnionSingle = direct("z")
const directUnionArray = direct(["z", "y"])
const nestedSingle = nested({fields: "z"})
const nestedUnionSingle = nestedUnion({fields: "z"})
const nestedUnionArray = nestedUnion({fields: ["z", "y"]})
declare function hasZField(arg: { z: string }): void
hasZField(directUnionSingle) // ok
hasZField(directUnionArray) // ok
hasZField(nestedSingle) // ok
hasZField(nestedUnionSingle) // ok
hasZField(nestedUnionArray) // ok
+8
View File
@@ -0,0 +1,8 @@
// @noLib: true
export function f() {
let e: {}[];
while (true) {
e = [...(e || [])];
}
}
@@ -0,0 +1,3 @@
class C {
type!: number;
}
@@ -0,0 +1,19 @@
// @jsx: preserve
namespace JSX {
export interface IntrinsicElements {
span: {};
}
export interface Element {
something?: any;
}
}
const Foo = (props: { foo: "A" | "B" | "C" }) => <span>{props.foo}</span>;
Foo({
foo: "B"
});
<Foo foo="B" />
@@ -0,0 +1,3 @@
declare function f<T>(predicate: (x: {}) => x is T): T;
// 'res' should be of type 'number'.
const res = f((n): n is number => true);
@@ -0,0 +1,3 @@
[true, true, false, null]
.filter((thing): thing is boolean => thing !== null)
.map(thing => thing.toString());
@@ -0,0 +1,14 @@
interface A {
pred(x: {}): x is boolean;
}
interface B {
pred(x: {}): x is string;
}
type Or = A | B;
function f(o: Or, x: {}) {
if (o.pred(x)) {
x;
}
}
@@ -0,0 +1,5 @@
declare function isString(x: any): x is string;
declare function isNumber(x: any): x is number;
declare function f(p: typeof isString | typeof isNumber): void;
f(isString);
f(isNumber);
@@ -0,0 +1,15 @@
interface A {
pred(x: {}, y: {}): x is boolean;
}
interface B {
pred(x: {}, y: {}): y is string;
}
type Or = A | B;
function f(o: Or, x: {}, y: {}) {
if (o.pred(x, y)) {
x;
y;
}
}
@@ -0,0 +1,13 @@
// @strict: true
// Repro from #20802
function x<T>(ctor: {
(this: {}, v: T): void;
new(v: T): void;
} | {
(v: T): void;
new(v: T): void;
}, t: T) {
new ctor(t);
}
@@ -0,0 +1,105 @@
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 {
let z: number | Object = x.b;
}
}
function anonymousClasses(x: { a: string; } | { b: number; }) {
if ("a" in x) {
let y: string = x.a;
} else {
let z: number = x.b;
}
}
class AWithOptionalProp { a?: string; }
class BWithOptionalProp { b?: string; }
function positiveTestClassesWithOptionalProperties(x: AWithOptionalProp | BWithOptionalProp) {
if ("a" in x) {
x.a = "1";
} else {
const y: string = x instanceof AWithOptionalProp
? x.a
: x.b
}
}
function inParenthesizedExpression(x: A | B) {
if ("a" in (x)) {
let y: string = x.a;
} else {
let z: number = x.b;
}
}
class ClassWithUnionProp { prop: A | B; }
function inProperty(x: ClassWithUnionProp) {
if ("a" in x.prop) {
let y: string = x.prop.a;
} else {
let z: number = x.prop.b;
}
}
class NestedClassWithProp { outer: ClassWithUnionProp; }
function innestedProperty(x: NestedClassWithProp) {
if ("a" in x.outer.prop) {
let y: string = x.outer.prop.a;
} else {
let z: number = x.outer.prop.b;
}
}
class InMemberOfClass {
protected prop: A | B;
inThis() {
if ("a" in this.prop) {
let y: string = this.prop.a;
} else {
let z: number = this.prop.b;
}
}
}
// added for completeness
class SelfAssert {
a: string;
inThis() {
if ("a" in this) {
let y: string = this.a;
} else {
}
}
}
interface Indexed {
[s: string]: any;
}
function f(i: Indexed) {
if ("a" in i) {
return i.a;
}
else if ("b" in i) {
return i.b;
}
return "c" in i && i.c;
}
@@ -296,6 +296,9 @@ define(function () {
isArray = ('isArray' in Array) ?
Array.isArray : function (value) { return Object.prototype.toString.call(value) === '[object Array]'; };
isArray = 'isArray' in Array
? function (value) { return Object.prototype.toString.call(value) === '[object Array]'; }
: Array.isArray;
function equalIC(a, b) {
return a != null && b != null && a.toLowerCase() === b.toLowerCase();
@@ -966,7 +969,7 @@ define(function () {
// should not be replaced by a completely new object - just overwrite existing methods
MobileDetect._impl = impl;
MobileDetect.version = '1.3.3 2016-07-31';
return MobileDetect;
@@ -3,6 +3,7 @@
// @module: amd
// @noLib: true
// @strictNullChecks: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
@@ -3,6 +3,7 @@
// @module: amd
// @noLib: true
// @strictNullChecks: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
@@ -0,0 +1,4 @@
0b00_11;
0B0_1;
0b1100_0011;
0B0_11_0101;
@@ -0,0 +1,18 @@
// @filename: 1.ts
0b00_
// @filename: 2.ts
0b_110
// @filename: 3.ts
0_B0101
// @filename: 4.ts
0b01__11
// @filename: 5.ts
0B0110_0110__
// @filename: 6.ts
0b___0111010_0101_1
@@ -0,0 +1,14 @@
1_000_000_000
1.1_00_01
1e1_0
1e+1_0
1e-1_0
1.1e10_0
1.1e+10_0
1.1e-10_0
12_34_56
1_22_333
1_2.3_4
1_2.3_4e5_6
1_2.3_4e+5_6
1_2.3_4e-5_6
@@ -0,0 +1,152 @@
// @filename: 1.ts
_10
// @filename: 2.ts
10_
// @filename: 3.ts
1__0
// @filename: 4.ts
0_.0
// @filename: 5.ts
0._0
// @filename: 6.ts
0.0__0
// @filename: 7.ts
0.0__
// @filename: 8.ts
0_e0
// @filename: 9.ts
0e_0
// @filename: 10.ts
0e0_
// @filename: 11.ts
0e0__0
// @filename: 12.ts
0_.0e0
// @filename: 13.ts
0._0e0
// @filename: 14.ts
0.0_e0
// @filename: 15.ts
0.0e_0
// @filename: 16.ts
_0.0e0
// @filename: 17.ts
0.0e0_
// @filename: 18.ts
0__0.0e0
// @filename: 19.ts
0.0__0e0
// @filename: 20.ts
0.00e0__0
// @filename: 21.ts
0_e+0
// @filename: 22.ts
0e+_0
// @filename: 23.ts
0e+0_
// @filename: 24.ts
0e+0__0
// @filename: 25.ts
0_.0e+0
// @filename: 26.ts
0._0e+0
// @filename: 27.ts
0.0_e+0
// @filename: 28.ts
0.0e+_0
// @filename: 29.ts
_0.0e+0
// @filename: 30.ts
0.0e+0_
// @filename: 31.ts
0__0.0e+0
// @filename: 32.ts
0.0__0e+0
// @filename: 33.ts
0.00e+0__0
// @filename: 34.ts
0_e+0
// @filename: 35.ts
0e-_0
// @filename: 36.ts
0e-0_
// @filename: 37.ts
0e-0__0
// @filename: 38.ts
0_.0e-0
// @filename: 39.ts
0._0e-0
// @filename: 40.ts
0.0_e-0
// @filename: 41.ts
0.0e-_0
// @filename: 42.ts
_0.0e-0
// @filename: 43.ts
0.0e-0_
// @filename: 44.ts
0__0.0e-0
// @filename: 45.ts
0.0__0e-0
// @filename: 46.ts
0.00e-0__0
// @filename: 47.ts
._
// @filename: 48.ts
1\u005F01234
// @filename: 49.ts
1.0e_+10
// @filename: 50.ts
1.0e_-10
// @filename: 51.ts
0._
@@ -0,0 +1,4 @@
0x00_11;
0X0_1;
0x1100_0011;
0X0_11_0101;
@@ -0,0 +1,18 @@
// @filename: 1.ts
0x00_
// @filename: 2.ts
0x_110
// @filename: 3.ts
0_X0101
// @filename: 4.ts
0x01__11
// @filename: 5.ts
0X0110_0110__
// @filename: 6.ts
0x___0111010_0101_1
@@ -0,0 +1,4 @@
0o00_11;
0O0_1;
0o1100_0011;
0O0_11_0101;
@@ -0,0 +1,18 @@
// @filename: 1.ts
0o00_
// @filename: 2.ts
0o_110
// @filename: 3.ts
0_O0101
// @filename: 4.ts
0o01__11
// @filename: 5.ts
0O0110_0110__
// @filename: 6.ts
0o___0111010_0101_1
@@ -0,0 +1,143 @@
// @filename: 1.ts
"\u{10_ffff}"
// @filename: 2.ts
'\u{10_ffff}'
// @filename: 3.ts
`\u{10_ffff}`
// @filename: 4.ts
/\u{10_ffff}/u
// @filename: 5.ts
"\uff_ff"
// @filename: 6.ts
'\uff_ff'
// @filename: 7.ts
`\uff_ff`
// @filename: 8.ts
/\uff_ff/u
// @filename: 9.ts
"\xf_f"
// @filename: 10.ts
'\xf_f'
// @filename: 11.ts
`\xf_f`
// @filename: 12.ts
/\xf_f/u
// @filename: 13.ts
"\u{_10ffff}"
// @filename: 14.ts
'\u{_10ffff}'
// @filename: 15.ts
`\u{_10ffff}`
// @filename: 16.ts
/\u{_10ffff}/u
// @filename: 17.ts
"\u_ffff"
// @filename: 18.ts
'\u_ffff'
// @filename: 19.ts
`\u_ffff`
// @filename: 20.ts
/\u_ffff/u
// @filename: 21.ts
"\x_ff"
// @filename: 22.ts
'\x_ff'
// @filename: 23.ts
`\x_ff`
// @filename: 24.ts
/\x_ff/u
// @filename: 25.ts
"\u{10ffff_}"
// @filename: 26.ts
'\u{10ffff_}'
// @filename: 27.ts
`\u{10ffff_}`
// @filename: 28.ts
/\u{10ffff_}/u
// @filename: 29.ts
"\uffff_"
// @filename: 30.ts
'\uffff_'
// @filename: 31.ts
`\uffff_`
// @filename: 32.ts
/\uffff_/u
// @filename: 33.ts
"\xff_"
// @filename: 34.ts
'\xff_'
// @filename: 35.ts
`\xff_`
// @filename: 36.ts
/\xff_/u
// @filename: 37.ts
"\u{10__ffff}"
// @filename: 38.ts
'\u{10__ffff}'
// @filename: 39.ts
`\u{10__ffff}`
// @filename: 40.ts
/\u{10__ffff}/u
// @filename: 41.ts
"\uff__ff"
// @filename: 42.ts
'\uff__ff'
// @filename: 43.ts
`\uff__ff`
// @filename: 44.ts
/\uff__ff/u
// @filename: 45.ts
"\xf__f"
// @filename: 46.ts
'\xf__f'
// @filename: 47.ts
`\xf__f`
// @filename: 48.ts
/\xf__f/u
@@ -0,0 +1,16 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es3
// @filename: index.js
Common.Item = class I {}
Common.Object = class extends Common.Item {}
Workspace.Object = class extends Common.Object {}
/** @type {Workspace.Object} */
var am;
// @filename: roots.js
var Common = {};
var Workspace = {};
@@ -0,0 +1,2 @@
declare let o: object;
const x: { a: number, b: number } = { a: 1, ...o, b: 2 };
@@ -9,6 +9,6 @@
////}
verify.codeFix({
description: "Call decorator expression.",
description: "Call decorator expression",
newRangeContent: `@foo()`
});
@@ -0,0 +1,23 @@
/// <reference path='fourslash.ts' />
////declare function foo(): (...args: any[]) => void;
////class C {
//// @foo
//// bar() {}
////
//// @foo
//// baz() {}
////}
verify.codeFixAll({
fixId: "addMissingInvocationForDecorator",
newFileContent:
`declare function foo(): (...args: any[]) => void;
class C {
@foo()
bar() {}
@foo()
baz() {}
}`
});
@@ -7,7 +7,7 @@
////}
verify.codeFix({
description: "Declare property 'foo'.",
description: "Declare property 'foo'",
index: 0,
// TODO: GH#18445
newFileContent: `class C {
@@ -7,7 +7,7 @@
////}
verify.codeFix({
description: "Add index signature for property 'foo'.",
description: "Add index signature for property 'foo'",
index: 1,
// TODO: GH#18445
newFileContent: `class C {
@@ -7,7 +7,7 @@
////}
verify.codeFix({
description: "Declare static property 'foo'.",
description: "Declare static property 'foo'",
index: 0,
// TODO: GH#18445
newFileContent: `class C {
@@ -13,11 +13,11 @@
////}
verify.codeFix({
description: "Initialize property 'foo' in the constructor.",
description: "Initialize property 'foo' in the constructor",
index: 0,
// TODO: GH#18445
newFileContent: `class C {
constructor() {
constructor() {\r
this.foo = undefined;\r
}
method() {
@@ -11,7 +11,7 @@
////}
verify.codeFix({
description: "Initialize static property 'foo'.",
description: "Initialize static property 'foo'",
index: 0,
// TODO: GH#18445
newFileContent: `class C {
@@ -11,11 +11,11 @@
////}
verify.codeFix({
description: "Initialize property 'foo' in the constructor.",
description: "Initialize property 'foo' in the constructor",
index: 0,
// TODO: GH#18445
newFileContent: `class C {
constructor() {
constructor() {\r
this.foo = undefined;\r
}
prop = ()=>{ this.foo === 10 };
@@ -9,7 +9,7 @@
////}
verify.codeFix({
description: "Initialize static property 'foo'.",
description: "Initialize static property 'foo'",
index: 2,
// TODO: GH#18445
newFileContent: `class C {
@@ -0,0 +1,26 @@
/// <reference path='fourslash.ts' />
////class C {
//// method() {
//// this.x = 0;
//// this.y();
//// this.x = "";
//// }
////}
verify.codeFixAll({
fixId: "addMissingMember",
newFileContent:
// TODO: GH#18445
`class C {
x: number;\r
y(): any {\r
throw new Error("Method not implemented.");\r
}\r
method() {
this.x = 0;
this.y();
this.x = "";
}
}`,
});
@@ -0,0 +1,33 @@
/// <reference path='fourslash.ts' />
// @allowJs: true
// @checkJs: true
// @Filename: /a.js
////class C {
//// constructor() {}
//// method() {
//// this.x;
//// this.y();
//// this.x;
//// }
////}
verify.codeFixAll({
fixId: "addMissingMember",
newFileContent:
// TODO: GH#18445
`class C {
y() {\r
throw new Error("Method not implemented.");\r
}\r
constructor() {\r
this.x = undefined;\r
}
method() {
this.x;
this.y();
this.x;
}
}`,
});
@@ -0,0 +1,31 @@
/// <reference path='fourslash.ts' />
// @moduleResolution: node
// @noImplicitAny: true
// @Filename: /node_modules/abs/index.js
////not read
// @Filename: /node_modules/zap/index.js
////not read
// @Filename: /a.ts
/////**/import * as abs from "abs";
////import * as zap from "zap";
test.setTypesRegistry({
"abs": undefined,
"zap": undefined,
});
goTo.marker();
verify.codeFixAll({
fixId: "fixCannotFindModule",
commands: [
{ packageName: "@types/abs", file: "/a.ts", type: "install package" },
{ packageName: "@types/zap", file: "/a.ts", type: "install package" },
],
newFileContent: `import * as abs from "abs";
import * as zap from "zap";` // unchanged
});
@@ -6,7 +6,7 @@
//// [|abstract class A extends I1 implements I2|] { }
verify.codeFix({
description: "Change 'extends' to 'implements'.",
description: "Change 'extends' to 'implements'",
// TODO: GH#18794
newRangeContent: "abstract class A implements I1 , I2",
});
@@ -4,6 +4,6 @@
////[|class C<T extends string , U> extends I<T>|]{}
verify.codeFix({
description: "Change 'extends' to 'implements'.",
description: "Change 'extends' to 'implements'",
newRangeContent: "class C<T extends string , U> implements I<T>",
});
@@ -11,7 +11,7 @@
//// @sealed
//// [|class A extends I1 implements I2 { }|]
verify.codeFix({
description: "Change 'extends' to 'implements'.",
description: "Change 'extends' to 'implements'",
// TODO: GH#18794
newRangeContent: "class A implements I1 , I2 { }",
});
@@ -2,6 +2,6 @@
//// var x: [|?|] = 12;
verify.codeFix({
description: "Change '?' to 'any'.",
description: "Change '?' to 'any'",
newRangeContent: "any",
});
@@ -4,7 +4,7 @@
//// }
verify.codeFix({
description: "Change 'number?' to 'number | null'.",
description: "Change 'number?' to 'number | null'",
errorCode: 8020,
index: 0,
newRangeContent: "number | null",
@@ -4,7 +4,7 @@
//// }
verify.codeFix({
description: "Change 'string?' to 'string | null | undefined'.",
description: "Change 'string?' to 'string | null | undefined'",
errorCode: 8020,
index: 1,
newRangeContent: "string | null | undefined",
@@ -5,7 +5,7 @@
////}
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
errorCode: 8020,
index: 0,
newRangeContent: "any",
@@ -5,7 +5,7 @@
////}
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
errorCode: 8020,
index: 0,
newRangeContent: "any",
@@ -3,7 +3,7 @@
//// var x = 12 as [|number?|];
verify.codeFix({
description: "Change 'number?' to 'number | null'.",
description: "Change 'number?' to 'number | null'",
errorCode: 8020,
index: 0,
newRangeContent: "number | null",
@@ -3,7 +3,7 @@
// note: without --strict, number? --> number, not number | null
verify.codeFix({
description: "Change 'function(number?): number' to '(arg0: number) => number'.",
description: "Change 'function(number?): number' to '(arg0: number) => number'",
errorCode: 8020,
index: 0,
newRangeContent: "(arg0: number) => number",
@@ -2,6 +2,6 @@
//// var f: { [K in keyof number]: [|*|] };
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// declare function index(ix: number): [|*|];
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// var index: { (ix: number): [|?|] };
verify.codeFix({
description: "Change '?' to 'any'.",
description: "Change '?' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// var index: { new (ix: number): [|?|] };
verify.codeFix({
description: "Change '?' to 'any'.",
description: "Change '?' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// var x: [|*|] = 12;
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// var index = { get p(): [|*|] { return 12 } };
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// var index = { set p(x: [|*|]) { } };
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// var index: { [s: string]: [|*|] };
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -5,6 +5,6 @@
////}
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -4,6 +4,6 @@
////}
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -4,6 +4,6 @@
////}
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -4,6 +4,6 @@
////}
verify.codeFix({
description: "Change '*' to 'any'.",
description: "Change '*' to 'any'",
newRangeContent: "any",
});
@@ -2,6 +2,6 @@
//// var x: [|Array.<number>|] = 12;
verify.codeFix({
description: "Change 'Array.<number>' to 'number[]'.",
description: "Change 'Array.<number>' to 'number[]'",
newRangeContent: "number[]",
});
@@ -3,7 +3,7 @@
//// var x: [|?number|] = 12;
verify.codeFix({
description: "Change '?number' to 'number | null'.",
description: "Change '?number' to 'number | null'",
errorCode: 8020,
index: 0,
newRangeContent: "number | null",
@@ -3,7 +3,7 @@
//// var x: [|number?|] = 12;
verify.codeFix({
description: "Change 'number?' to 'number | null | undefined'.",
description: "Change 'number?' to 'number | null | undefined'",
index: 1,
newRangeContent: "number | null | undefined",
});
@@ -2,6 +2,6 @@
//// var x: [|!number|] = 12;
verify.codeFix({
description: "Change '!number' to 'number'.",
description: "Change '!number' to 'number'",
newRangeContent: "number",
});
@@ -2,6 +2,6 @@
//// var x: [|function(this: number, number): string|] = 12;
verify.codeFix({
description: "Change 'function(this: number, number): string' to '(this: number, arg1: number) => string'.",
description: "Change 'function(this: number, number): string' to '(this: number, arg1: number) => string'",
newRangeContent: "(this: number, arg1: number) => string",
});
@@ -2,6 +2,6 @@
//// var x: [|function(new: number)|] = 12;
verify.codeFix({
description: "Change 'function(new: number)' to 'new () => number'.",
description: "Change 'function(new: number)' to 'new () => number'",
newRangeContent: "new () => number",
});
@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
// @strict: true
////function f(a: ?number, b: string!) {}
verify.codeFixAll({
fixId: "fixJSDocTypes_plain",
newFileContent: "function f(a: number | null, b: string) {}",
})
@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
// @strict: true
////function f(a: ?number, b: string!) {}
verify.codeFixAll({
fixId: "fixJSDocTypes_nullable",
newFileContent: "function f(a: number | null | undefined, b: string) {}",
})
@@ -3,14 +3,18 @@
////class A {
//// f() {}
////}
////
////let B = class implements A {[| |]}
////let B = class implements A {}
verify.codeFix({
description: "Implement interface 'A'.",
description: "Implement interface 'A'",
// TODO: GH#18795
newRangeContent: `f(): void {\r
throw new Error("Method not implemented.");\r
}\r
`
newFileContent:
`class A {
f() {}
}
let B = class implements A {\r
f(): void {\r
throw new Error("Method not implemented.");\r
}\r
}`
});
@@ -7,11 +7,20 @@
//// return C;
////}
////
////let B = class extends foo("s")<number> {[| |]}
////let B = class extends foo("s")<number> {}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `a: string | number;\r
`
newFileContent:
`function foo<T>(a: T) {
abstract class C<U> {
abstract a: T | U;
}
return C;
}
let B = class extends foo("s")<number> {\r
a: string | number;\r
}`
});
@@ -10,8 +10,17 @@
////class B extends foo("s")<number> {[| |]}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `a: string | number;\r
`
newFileContent:
`function foo<T>(a: T) {
abstract class C<U> {
abstract a: T | U;
}
return C;
}
class B extends foo("s")<number> {\r
a: string | number;\r
}`
});
@@ -18,17 +18,37 @@
////// Don't need to add anything in this case.
////abstract class B extends A {}
////
////class C extends A {[| |]}
////class C extends A {}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `a: string | number;\r
b: this;\r
c: A;\r
d: string | number;\r
e: this;\r
f: A;\r
g: string;\r
`
newFileContent:
`abstract class A {
private _a: string;
abstract get a(): number | string;
abstract get b(): this;
abstract get c(): A;
abstract set d(arg: number | string);
abstract set e(arg: this);
abstract set f(arg: A);
abstract get g(): string;
abstract set g(newName: string);
}
// Don't need to add anything in this case.
abstract class B extends A {}
class C extends A {\r
a: string | number;\r
b: this;\r
c: A;\r
d: string | number;\r
e: this;\r
f: A;\r
g: string;\r
}`
});
@@ -8,20 +8,30 @@
//// abstract foo(): number;
////}
////
////class C extends A {[| |]}
////class C extends A {}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `f(a: number, b: string): boolean;\r
f(a: number, b: string): this;\r
f(a: string, b: number): Function;\r
f(a: string): Function;\r
f(a: any, b?: any) {\r
throw new Error("Method not implemented.");\r
}\r
foo(): number {\r
throw new Error("Method not implemented.");\r
}\r
`
newFileContent:
`abstract class A {
abstract f(a: number, b: string): boolean;
abstract f(a: number, b: string): this;
abstract f(a: string, b: number): Function;
abstract f(a: string): Function;
abstract foo(): number;
}
class C extends A {\r
f(a: number, b: string): boolean;\r
f(a: number, b: string): this;\r
f(a: string, b: number): Function;\r
f(a: string): Function;\r
f(a: any, b?: any) {\r
throw new Error("Method not implemented.");\r
}\r
foo(): number {\r
throw new Error("Method not implemented.");\r
}\r
}`
});
@@ -4,13 +4,19 @@
//// abstract f(): this;
////}
////
////class C extends A {[| |]}
////class C extends A {}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `f(): this {\r
throw new Error("Method not implemented.");\r
}\r
`
newFileContent:
`abstract class A {
abstract f(): this;
}
class C extends A {\r
f(): this {\r
throw new Error("Method not implemented.");\r
}\r
}`
});
@@ -4,13 +4,19 @@
//// abstract f(x: T): T;
////}
////
////class C extends A<number> {[| |]}
////class C extends A<number> {}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `f(x: number): number {\r
throw new Error("Method not implemented.");\r
}\r
`
newFileContent:
`abstract class A<T> {
abstract f(x: T): T;
}
class C extends A<number> {\r
f(x: number): number {\r
throw new Error("Method not implemented.");\r
}\r
}`
});
@@ -4,13 +4,19 @@
//// abstract f(x: T): T;
////}
////
////class C<U> extends A<U> {[| |]}
////class C<U> extends A<U> {}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `f(x: U): U {\r
throw new Error("Method not implemented.");\r
}\r
`
newFileContent:
`abstract class A<T> {
abstract f(x: T): T;
}
class C<U> extends A<U> {\r
f(x: U): U {\r
throw new Error("Method not implemented.");\r
}\r
}`
});
@@ -0,0 +1,26 @@
/// <reference path='fourslash.ts' />
////abstract class A {
//// abstract m(): void;
////}
////class B extends A {}
////class C extends A {}
verify.codeFixAll({
fixId: "fixClassDoesntImplementInheritedAbstractMember",
// TODO: GH#18445
newFileContent:
`abstract class A {
abstract m(): void;
}
class B extends A {\r
m(): void {\r
throw new Error("Method not implemented.");\r
}\r
}
class C extends A {\r
m(): void {\r
throw new Error("Method not implemented.");\r
}\r
}`,
});
@@ -6,13 +6,21 @@
//// abstract z: A;
////}
////
////class C extends A {[| |]}
////class C extends A {}
verify.codeFix({
description: "Implement inherited abstract class.",
description: "Implement inherited abstract class",
// TODO: GH#18795
newRangeContent: `x: number;\r
y: this;\r
z: A;\r
`
newFileContent:
`abstract class A {
abstract x: number;
abstract y: this;
abstract z: A;
}
class C extends A {\r
x: number;\r
y: this;\r
z: A;\r
}`
});
@@ -1,11 +1,20 @@
/// <reference path='fourslash.ts' />
//// abstract class A {
////abstract class A {
//// abstract x: this;
//// }
////}
////
//// class C extends A {[| |]}
////class C extends A {[| |]}
verify.rangeAfterCodeFix(`
x: this;
`);
verify.codeFix({
description: "Implement inherited abstract class",
// TODO: GH#18445
newFileContent:
`abstract class A {
abstract x: this;
}
class C extends A {\r
x: this;\r
}`,
});
@@ -1,11 +1,20 @@
/// <reference path='fourslash.ts' />
//// abstract class A {
////abstract class A {
//// protected abstract x: number;
//// }
////}
////
//// class C extends A {[| |]}
////class C extends A {[| |]}
verify.rangeAfterCodeFix(`
protected x: number;
`);
verify.codeFix({
description: "Implement inherited abstract class",
// TODO: GH#18445
newFileContent:
`abstract class A {
protected abstract x: number;
}
class C extends A {\r
protected x: number;\r
}`,
});
@@ -1,12 +1,20 @@
/// <reference path='fourslash.ts' />
//// abstract class A {
////abstract class A {
//// public abstract x: number;
//// }
////}
////
//// class C extends A {[| |]}
////class C extends A {[| |]}
verify.codeFix({
description: "Implement inherited abstract class",
// TODO: GH#18445
newFileContent:
`abstract class A {
public abstract x: number;
}
verify.rangeAfterCodeFix(`
public x: number;
`);
class C extends A {\r
public x: number;\r
}`,
});
@@ -1,20 +1,36 @@
/// <reference path='fourslash.ts' />
//// abstract class A {
//// private _a: string;
////
//// abstract get a(): string;
//// abstract set a(newName: string);
////
//// abstract get b(): number;
////
//// abstract set c(arg: number | string);
//// }
////abstract class A {
//// private _a: string;
////
//// class C implements A {[| |]}
//// abstract get a(): string;
//// abstract set a(newName: string);
////
//// abstract get b(): number;
////
//// abstract set c(arg: number | string);
////}
////
////class C implements A {}
verify.rangeAfterCodeFix(`
a: string;
b: number;
c: string | number;
`);
verify.codeFix({
description: "Implement interface 'A'",
// TODO: GH#18445
newFileContent:
`abstract class A {
private _a: string;
abstract get a(): string;
abstract set a(newName: string);
abstract get b(): number;
abstract set c(arg: number | string);
}
class C implements A {\r
a: string;\r
b: number;\r
c: string | number;\r
}`,
});
@@ -1,13 +1,22 @@
/// <reference path='fourslash.ts' />
//// class A {
//// f() {}
//// }
////class A {
//// f() {}
////}
////
//// class B implements A {[| |]}
////class B implements A {[| |]}
verify.rangeAfterCodeFix(`
f(): void{
throw new Error("Method not implemented.");
verify.codeFix({
description: "Implement interface 'A'",
// TODO: GH#18445
newFileContent:
`class A {
f() {}
}
`);
class B implements A {\r
f(): void {\r
throw new Error("Method not implemented.");\r
}\r
}`,
});

Some files were not shown because too many files have changed in this diff Show More