mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Merge branch 'master' into ownJsonParsing
This commit is contained in:
commit
0bbbc518bc
1383 files changed
+51123
-39727
No files matched your search
@@ -0,0 +1,2 @@
|
||||
var arr: string[] | number[];
|
||||
arr.splice(1, 1);
|
||||
@@ -8,3 +8,69 @@ async function fAsyncExplicit(): Promise<[number, boolean]> {
|
||||
// This is contextually typed as a tuple.
|
||||
return [1, true];
|
||||
}
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/13128
|
||||
interface Obj {
|
||||
stringProp: string;
|
||||
anyProp: any;
|
||||
}
|
||||
|
||||
async function fIndexedTypeForStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
return obj.stringProp;
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
return Promise.resolve<Obj["stringProp"]>(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fIndexedTypeForAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
return obj.anyProp;
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
return Promise.resolve<Obj["anyProp"]>(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
return obj.stringProp;
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
return Promise.resolve<TObj["stringProp"]>(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
return obj.anyProp;
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
return Promise.resolve<TObj["anyProp"]>(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
return obj[key];
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
return Promise.resolve(obj[key]);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
return Promise.resolve<TObj[K]>(obj[key]);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
interface A {
|
||||
readonly b
|
||||
}
|
||||
var a: A = {
|
||||
b: 123
|
||||
};
|
||||
|
||||
delete a.b;
|
||||
|
||||
interface B {
|
||||
readonly [k: string]: string
|
||||
}
|
||||
|
||||
var b: B = {
|
||||
'test': 'test'
|
||||
};
|
||||
|
||||
delete b['test'];
|
||||
|
||||
delete ((((b['test']))));
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target: ES3
|
||||
enum E {
|
||||
x = -01,
|
||||
y = 02,
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,5 @@
|
||||
// @target: ES5
|
||||
enum E {
|
||||
x = -01,
|
||||
y = 02,
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// @importHelpers: true
|
||||
// @target: es5
|
||||
|
||||
// @filename: a.d.ts
|
||||
export { };
|
||||
|
||||
// Extends
|
||||
declare class C { }
|
||||
declare class D extends C { }
|
||||
|
||||
// Destructuring
|
||||
interface I {
|
||||
({descendants, read}?: {
|
||||
descendants?: boolean;
|
||||
read?: any;
|
||||
}): any;
|
||||
}
|
||||
|
||||
|
||||
// Object Rest
|
||||
interface Foo {
|
||||
a: number; b: string;
|
||||
}
|
||||
export var { a, ...x } : Foo;
|
||||
|
||||
// @filename: b.ts
|
||||
export {};
|
||||
declare namespace N {
|
||||
// Extends
|
||||
class C { }
|
||||
class D extends C { }
|
||||
|
||||
// Destructuring
|
||||
interface I {
|
||||
({descendants, read}?: {
|
||||
descendants?: boolean;
|
||||
read?: any;
|
||||
}): any;
|
||||
}
|
||||
|
||||
|
||||
// Object Rest
|
||||
interface Foo {
|
||||
a: number; b: string;
|
||||
}
|
||||
export var { a, ...x } : Foo;
|
||||
}
|
||||
|
||||
// @filename: tslib.d.ts
|
||||
export declare function __extends(d: Function, b: Function): void;
|
||||
export declare function __assign(t: any, ...sources: any[]): any;
|
||||
export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any;
|
||||
export declare function __param(paramIndex: number, decorator: Function): Function;
|
||||
export declare function __metadata(metadataKey: any, metadataValue: any): Function;
|
||||
export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any;
|
||||
@@ -0,0 +1,9 @@
|
||||
//@jsx: react
|
||||
|
||||
declare var React: any;
|
||||
<View>
|
||||
<ListView refreshControl={
|
||||
<RefreshControl onRefresh={} refreshing={} />
|
||||
} dataSource={this.state.ds} renderRow={}>
|
||||
</ListView>
|
||||
</View>
|
||||
@@ -0,0 +1,12 @@
|
||||
// @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>;
|
||||
}
|
||||
}) {}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Repro from #13346
|
||||
|
||||
interface Chainable<T> {
|
||||
value(): T;
|
||||
mapValues<U>(func: (v: T[keyof T]) => U): Chainable<{[k in keyof T]: U}>;
|
||||
}
|
||||
|
||||
declare function chain<T>(t: T): Chainable<T>;
|
||||
|
||||
const square = (x: number) => x * x;
|
||||
|
||||
const v = chain({a: 1, b: 2}).mapValues(square).value();
|
||||
@@ -0,0 +1,18 @@
|
||||
// Repro from #13351
|
||||
|
||||
type Meta<T, A> = {
|
||||
readonly[P in keyof T]: {
|
||||
value: T[P];
|
||||
also: A;
|
||||
readonly children: Meta<T[P], A>;
|
||||
};
|
||||
}
|
||||
|
||||
interface Input {
|
||||
x: string;
|
||||
y: number;
|
||||
}
|
||||
|
||||
declare const output: Meta<Input, boolean>;
|
||||
|
||||
const shouldFail: { important: boolean } = output.x.children;
|
||||
@@ -0,0 +1,14 @@
|
||||
// @experimentalDecorators: true
|
||||
// @emitDecoratorMetadata: true
|
||||
// @target: es5
|
||||
module MyModule {
|
||||
|
||||
export function inject(target: any, key: string): void { }
|
||||
|
||||
export class Leg { }
|
||||
|
||||
export class Person {
|
||||
@inject leftLeg: Leg;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
class A<T extends T> {
|
||||
foo() {
|
||||
var x: T;
|
||||
// no error expected below this line
|
||||
var a = x.foo();
|
||||
var b = new x(123);
|
||||
var c = x[1];
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
let a: number;
|
||||
let b: typeof a;
|
||||
@@ -0,0 +1,18 @@
|
||||
//@noUnusedLocals:true
|
||||
|
||||
declare let props: any;
|
||||
const {
|
||||
children, // here!
|
||||
active: _a, // here!
|
||||
...rest,
|
||||
} = props;
|
||||
|
||||
function foo() {
|
||||
const {
|
||||
children,
|
||||
active: _a,
|
||||
...rest,
|
||||
} = props;
|
||||
}
|
||||
|
||||
export const asdf = 123;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
const [a, b = a] = [1]; // ok
|
||||
const [c, d = c, e = e] = [1]; // error for e = e
|
||||
const [f, g = f, h = i, i = f] = [1]; // error for h = i
|
||||
|
||||
(function ([a, b = a]) { // ok
|
||||
})([1]);
|
||||
(function ([c, d = c, e = e]) { // error for e = e
|
||||
})([1]);
|
||||
(function ([f, g = f, h = i, i = f]) { // error for h = i
|
||||
})([1])
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
const {
|
||||
a = 1,
|
||||
b = 2,
|
||||
c = b, // ok
|
||||
d = a, // ok
|
||||
e = f, // error
|
||||
f = f // error
|
||||
} = { } as any;
|
||||
@@ -0,0 +1,25 @@
|
||||
// @target: es5
|
||||
const a = new.target;
|
||||
const b = () => new.target;
|
||||
|
||||
class C {
|
||||
[new.target]() { }
|
||||
c() { return new.target; }
|
||||
get d() { return new.target; }
|
||||
set e(_) { _ = new.target; }
|
||||
f = () => new.target;
|
||||
|
||||
static [new.target]() { }
|
||||
static g() { return new.target; }
|
||||
static get h() { return new.target; }
|
||||
static set i(_) { _ = new.target; }
|
||||
static j = () => new.target;
|
||||
}
|
||||
|
||||
const O = {
|
||||
[new.target]: undefined,
|
||||
k() { return new.target; },
|
||||
get l() { return new.target; },
|
||||
set m(_) { _ = new.target; },
|
||||
n: new.target,
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
// @target: es6
|
||||
const a = new.target;
|
||||
const b = () => new.target;
|
||||
|
||||
class C {
|
||||
[new.target]() { }
|
||||
c() { return new.target; }
|
||||
get d() { return new.target; }
|
||||
set e(_) { _ = new.target; }
|
||||
f = () => new.target;
|
||||
|
||||
static [new.target]() { }
|
||||
static g() { return new.target; }
|
||||
static get h() { return new.target; }
|
||||
static set i(_) { _ = new.target; }
|
||||
static j = () => new.target;
|
||||
}
|
||||
|
||||
const O = {
|
||||
[new.target]: undefined,
|
||||
k() { return new.target; },
|
||||
get l() { return new.target; },
|
||||
set m(_) { _ = new.target; },
|
||||
n: new.target,
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
// @target: es5
|
||||
class A {
|
||||
constructor() {
|
||||
const a = new.target;
|
||||
const b = () => new.target;
|
||||
}
|
||||
static c = function () { return new.target; }
|
||||
d = function () { return new.target; }
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
super();
|
||||
const e = new.target;
|
||||
const f = () => new.target;
|
||||
}
|
||||
}
|
||||
|
||||
function f1() {
|
||||
const g = new.target;
|
||||
const h = () => new.target;
|
||||
}
|
||||
|
||||
const f2 = function () {
|
||||
const i = new.target;
|
||||
const j = () => new.target;
|
||||
}
|
||||
|
||||
const O = {
|
||||
k: function () { return new.target; }
|
||||
};
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// @target: es6
|
||||
class A {
|
||||
constructor() {
|
||||
const a = new.target;
|
||||
const b = () => new.target;
|
||||
}
|
||||
static c = function () { return new.target; }
|
||||
d = function () { return new.target; }
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
super();
|
||||
const e = new.target;
|
||||
const f = () => new.target;
|
||||
}
|
||||
}
|
||||
|
||||
function f1() {
|
||||
const g = new.target;
|
||||
const h = () => new.target;
|
||||
}
|
||||
|
||||
const f2 = function () {
|
||||
const i = new.target;
|
||||
const j = () => new.target;
|
||||
}
|
||||
|
||||
const O = {
|
||||
k: function () { return new.target; }
|
||||
};
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
declare class StaticToString {
|
||||
static toString(): void;
|
||||
}
|
||||
|
||||
function foo(staticToString: StaticToString) {
|
||||
return staticToString instanceof StaticToString;
|
||||
}
|
||||
|
||||
declare class StaticToNumber {
|
||||
static toNumber(): void;
|
||||
}
|
||||
function bar(staticToNumber: StaticToNumber) {
|
||||
return staticToNumber instanceof StaticToNumber;
|
||||
}
|
||||
|
||||
declare class NormalToString {
|
||||
toString(): void;
|
||||
}
|
||||
function baz(normal: NormalToString) {
|
||||
return normal instanceof NormalToString;
|
||||
}
|
||||
@@ -27,3 +27,6 @@
|
||||
// contextually typed parameters.
|
||||
let twelve = (f => f(12))(i => i);
|
||||
let eleven = (o => o.a(11))({ a: function(n) { return n; } });
|
||||
// missing arguments
|
||||
(function(x, undefined) { return x; })(42);
|
||||
((x, y, z) => 42)();
|
||||
@@ -0,0 +1,33 @@
|
||||
// @strictNullChecks: true
|
||||
// arrow
|
||||
(jake => { })("build");
|
||||
// function expression
|
||||
(function (cats) { })("lol");
|
||||
// Lots of Irritating Superfluous Parentheses
|
||||
(function (x) { } ("!"));
|
||||
((((function (y) { }))))("-");
|
||||
// multiple arguments
|
||||
((a, b, c) => { })("foo", 101, false);
|
||||
// default parameters
|
||||
((m = 10) => m + 1)(12);
|
||||
((n = 10) => n + 1)();
|
||||
// optional parameters
|
||||
((j?) => j + 1)(12);
|
||||
((k?) => k + 1)();
|
||||
((l, o?) => l + o)(12); // o should be any
|
||||
// rest parameters
|
||||
((...numbers) => numbers.every(n => n > 0))(5,6,7);
|
||||
((...mixed) => mixed.every(n => !!n))(5,'oops','oh no');
|
||||
((...noNumbers) => noNumbers.some(n => n > 0))();
|
||||
((first, ...rest) => first ? [] : rest.map(n => n > 0))(8,9,10);
|
||||
// destructuring parameters (with defaults too!)
|
||||
(({ q }) => q)({ q : 13 });
|
||||
(({ p = 14 }) => p)({ p : 15 });
|
||||
(({ r = 17 } = { r: 18 }) => r)({r : 19});
|
||||
(({ u = 22 } = { u: 23 }) => u)();
|
||||
// contextually typed parameters.
|
||||
let twelve = (f => f(12))(i => i);
|
||||
let eleven = (o => o.a(11))({ a: function(n) { return n; } });
|
||||
// missing arguments
|
||||
(function(x, undefined) { return x; })(42);
|
||||
((x, y, z) => 42)();
|
||||
@@ -42,7 +42,7 @@ var p = 0;
|
||||
<div>
|
||||
</div>;
|
||||
|
||||
// Emit "foo" + ' ' + "bar"
|
||||
// Emit "foo bar"
|
||||
<div>
|
||||
|
||||
foo
|
||||
@@ -51,3 +51,15 @@ var p = 0;
|
||||
|
||||
</div>;
|
||||
|
||||
// Emit "hello\\ world"
|
||||
<div>
|
||||
|
||||
hello\
|
||||
|
||||
world
|
||||
</div>;
|
||||
|
||||
// Emit " a b c d "
|
||||
<div> a
|
||||
b c
|
||||
d </div>;
|
||||
@@ -0,0 +1,27 @@
|
||||
//@jsx: preserve
|
||||
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
interface TodoProp {
|
||||
id: number;
|
||||
todo: string;
|
||||
}
|
||||
interface TodoListProps {
|
||||
todos: TodoProp[];
|
||||
}
|
||||
function Todo(prop: { key: number, todo: string }) {
|
||||
return <div>{prop.key.toString() + prop.todo}</div>;
|
||||
}
|
||||
function TodoList({ todos }: TodoListProps) {
|
||||
return <div>
|
||||
{...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)}
|
||||
</div>;
|
||||
}
|
||||
let x: TodoListProps;
|
||||
<TodoList {...x}/>
|
||||
@@ -0,0 +1,32 @@
|
||||
// @jsx: react
|
||||
declare module JSX {
|
||||
interface Element { }
|
||||
interface IntrinsicElements {
|
||||
[s: string]: any;
|
||||
}
|
||||
}
|
||||
declare var React: any;
|
||||
|
||||
interface TodoProp {
|
||||
id: number;
|
||||
todo: string;
|
||||
}
|
||||
interface TodoListProps {
|
||||
todos: TodoProp[];
|
||||
}
|
||||
function Todo(prop: { key: number, todo: string }) {
|
||||
return <div>{prop.key.toString() + prop.todo}</div>;
|
||||
}
|
||||
function TodoList({ todos }: TodoListProps) {
|
||||
return <div>
|
||||
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
|
||||
</div>;
|
||||
}
|
||||
function TodoListNoError({ todos }: TodoListProps) {
|
||||
// any is not checked
|
||||
return <div>
|
||||
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
|
||||
</div>;
|
||||
}
|
||||
let x: TodoListProps;
|
||||
<TodoList {...x}/>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace Foo {
|
||||
export default foo;
|
||||
}
|
||||
|
||||
module Bar {
|
||||
export default bar;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ declare let x2: T2<"x">;
|
||||
let x2x = x2.x;
|
||||
|
||||
interface T3<T extends T3<T>> {
|
||||
x: T["x"]; // Error
|
||||
x: T["x"];
|
||||
}
|
||||
|
||||
interface T4<T extends T4<T>> {
|
||||
@@ -25,7 +25,16 @@ class C1 {
|
||||
}
|
||||
|
||||
class C2 {
|
||||
x: this["y"]; // Error
|
||||
y: this["z"]; // Error
|
||||
z: this["x"]; // Error
|
||||
}
|
||||
x: this["y"];
|
||||
y: this["z"];
|
||||
z: this["x"];
|
||||
}
|
||||
|
||||
// Repro from #12627
|
||||
|
||||
interface Foo {
|
||||
hello: boolean;
|
||||
}
|
||||
|
||||
function foo<T extends Foo | T["hello"]>() {
|
||||
}
|
||||
@@ -297,6 +297,30 @@ class C1 {
|
||||
}
|
||||
}
|
||||
|
||||
type S2 = {
|
||||
a: string;
|
||||
b: string;
|
||||
};
|
||||
|
||||
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) {
|
||||
x1 = x2;
|
||||
x1 = x3;
|
||||
x1 = x4;
|
||||
x2 = x1;
|
||||
x2 = x3;
|
||||
x2 = x4;
|
||||
x3 = x1;
|
||||
x3 = x2;
|
||||
x3 = x4;
|
||||
x4 = x1;
|
||||
x4 = x2;
|
||||
x4 = x3;
|
||||
x1.length;
|
||||
x2.length;
|
||||
x3.length;
|
||||
x4.length;
|
||||
}
|
||||
|
||||
// Repros from #12011
|
||||
|
||||
class Base {
|
||||
@@ -430,4 +454,50 @@ type SomeMethodDescriptor = {
|
||||
returnValue: string[];
|
||||
}
|
||||
|
||||
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
|
||||
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
|
||||
|
||||
// Repro from #13073
|
||||
|
||||
type KeyTypes = "a" | "b"
|
||||
let MyThingy: { [key in KeyTypes]: string[] };
|
||||
|
||||
function addToMyThingy<S extends KeyTypes>(key: S) {
|
||||
MyThingy[key].push("a");
|
||||
}
|
||||
|
||||
// Repro from #13102
|
||||
|
||||
type Handler<T> = {
|
||||
onChange: (name: keyof T) => void;
|
||||
};
|
||||
|
||||
function onChangeGenericFunction<T>(handler: Handler<T & {preset: number}>) {
|
||||
handler.onChange('preset')
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds<T extends Record<K, string>, K extends string>(
|
||||
obj: T,
|
||||
idFields: K[],
|
||||
idMapping: { [oldId: string]: string }
|
||||
): Record<K, string> {
|
||||
for (const idField of idFields) {
|
||||
const newId = idMapping[obj[idField]];
|
||||
if (newId) {
|
||||
obj[idField] = newId;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Repro from #13285
|
||||
|
||||
function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
|
||||
obj: T,
|
||||
key: K,
|
||||
stringMap: { [oldId: string]: string }
|
||||
) {
|
||||
var x = obj[key];
|
||||
stringMap[x]; // Should be OK.
|
||||
}
|
||||
@@ -105,4 +105,66 @@ function f50<T extends ItemMap>(obj: T, key: keyof T) {
|
||||
function f51<T extends ItemMap, K extends keyof T>(obj: T, key: K) {
|
||||
let item: Item = obj[key];
|
||||
return obj[key].name;
|
||||
}
|
||||
}
|
||||
|
||||
type T1<T> = {
|
||||
[P in keyof T]: T[P];
|
||||
}
|
||||
|
||||
type T2<T> = {
|
||||
[P in keyof T]: T[P];
|
||||
}
|
||||
|
||||
function f60<U>(x: T1<U>, y: T2<U>) {
|
||||
x = y;
|
||||
y = x;
|
||||
}
|
||||
|
||||
type Identity<T> = {
|
||||
[P in keyof T]: T[P];
|
||||
}
|
||||
|
||||
function f61<U>(x: Identity<U>, y: Partial<U>) {
|
||||
x = y; // Error
|
||||
y = x;
|
||||
}
|
||||
|
||||
function f62<U>(x: Identity<U>, y: Readonly<U>) {
|
||||
x = y;
|
||||
y = x;
|
||||
}
|
||||
|
||||
function f70<T>(x: { [P in keyof T]: T[P] }, y: { [P in keyof T]: T[P] }) {
|
||||
x = y;
|
||||
y = x;
|
||||
}
|
||||
|
||||
function f71<T, U extends T>(x: { [P in keyof T]: T[P] }, y: { [P in keyof T]: U[P] }) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
function f72<T, U extends T>(x: { [P in keyof T]: T[P] }, y: { [P in keyof U]: U[P] }) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
function f73<T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in keyof T]: T[P] }) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
function f74<T, U extends T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in keyof U]: U[P] }) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
function f75<T, U extends T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in keyof T]: U[P] }) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
function f76<T, U extends T, K extends keyof T>(x: { [P in K]: T[P] }, y: { [P in K]: U[P] }) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
@@ -59,4 +59,15 @@ type DeepReadonlyFoo = {
|
||||
};
|
||||
|
||||
var x1: DeepReadonly<Foo>;
|
||||
var x1: DeepReadonlyFoo;
|
||||
var x1: DeepReadonlyFoo;
|
||||
|
||||
// Repro from #13232
|
||||
|
||||
type Z = { a: number };
|
||||
type Clone<T> = {
|
||||
[P in keyof (T & {})]: T[P];
|
||||
};
|
||||
type M = Clone<Z>; // M should be { a: number }
|
||||
|
||||
var z1: Z;
|
||||
var z1: Clone<Z>;
|
||||
@@ -0,0 +1,5 @@
|
||||
var x = {};
|
||||
var y = {foo: "bar"};
|
||||
var a: object;
|
||||
a = x;
|
||||
a = y;
|
||||
@@ -0,0 +1,3 @@
|
||||
var a: object;
|
||||
a.toString();
|
||||
a.nonExist(); // error
|
||||
@@ -0,0 +1,8 @@
|
||||
// @declaration: true
|
||||
interface WithNonPrimitive {
|
||||
foo: object
|
||||
}
|
||||
|
||||
var a: WithNonPrimitive = { foo: {bar: "bar"} };
|
||||
|
||||
var b: WithNonPrimitive = {foo: "bar"}; // expect error
|
||||
@@ -0,0 +1,27 @@
|
||||
var x = {};
|
||||
var y = {foo: "bar"};
|
||||
var a: object;
|
||||
x = a;
|
||||
y = a; // expect error
|
||||
a = x;
|
||||
a = y;
|
||||
|
||||
var n = 123;
|
||||
var b = true;
|
||||
var s = "fooo";
|
||||
|
||||
a = n; // expect error
|
||||
a = b; // expect error
|
||||
a = s; // expect error
|
||||
|
||||
n = a; // expect error
|
||||
b = a; // expect error
|
||||
s = a; // expect error
|
||||
|
||||
var numObj: Number = 123;
|
||||
var boolObj: Boolean = true;
|
||||
var strObj: String = "string";
|
||||
|
||||
a = numObj; // ok
|
||||
a = boolObj; // ok
|
||||
a = strObj; // ok
|
||||
@@ -0,0 +1,19 @@
|
||||
// @declaration: true
|
||||
function takeObject(o: object) {}
|
||||
function returnObject(): object {
|
||||
return {};
|
||||
}
|
||||
|
||||
var nonPrimitive: object;
|
||||
var primitive: boolean;
|
||||
|
||||
takeObject(nonPrimitive);
|
||||
nonPrimitive = returnObject();
|
||||
|
||||
takeObject(primitive); // expect error
|
||||
primitive = returnObject(); // expect error
|
||||
|
||||
function returnError(): object {
|
||||
var ret = 123;
|
||||
return ret; // expect error
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// @declaration: true
|
||||
function generic<T>(t: T) {
|
||||
var o: object = t; // expect error
|
||||
}
|
||||
var a = {};
|
||||
var b = "42";
|
||||
|
||||
generic<object>({});
|
||||
generic<object>(a);
|
||||
generic<object>(123); // expect error
|
||||
generic<object>(b); // expect error
|
||||
|
||||
function bound<T extends object>(t: T) {
|
||||
var o: object = t; // ok
|
||||
}
|
||||
|
||||
bound({});
|
||||
bound(a);
|
||||
bound(123); // expect error
|
||||
bound(b); // expect error
|
||||
|
||||
function bound2<T extends object>() {}
|
||||
|
||||
bound2<{}>();
|
||||
bound2<Object>();
|
||||
bound2<number>(); // expect error
|
||||
bound2<string>(); // expect error
|
||||
|
||||
function bound3<T extends {}>(t: T) {
|
||||
var o: object = t; // ok
|
||||
}
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
var y: Proxy<null>; // ok
|
||||
var z: Proxy<undefined> ; // ok
|
||||
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
@@ -0,0 +1,22 @@
|
||||
class Narrow {
|
||||
narrowed: boolean
|
||||
}
|
||||
|
||||
var a: object
|
||||
|
||||
if (a instanceof Narrow) {
|
||||
a.narrowed; // ok
|
||||
a = 123; // error
|
||||
}
|
||||
|
||||
if (typeof a === 'number') {
|
||||
a.toFixed(); // error, never
|
||||
}
|
||||
|
||||
var b: object | null
|
||||
|
||||
if (typeof b === 'object') {
|
||||
b.toString(); // ok, object | null
|
||||
} else {
|
||||
b.toString(); // error, never
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
var a: object
|
||||
declare var b: object | null
|
||||
declare var c: object | undefined
|
||||
declare var d: object | null | undefined
|
||||
var e: object | null
|
||||
a.toString; // error
|
||||
a = undefined; // error
|
||||
a = null; // error
|
||||
a = b; // error
|
||||
a = c; // error
|
||||
a = d; // error
|
||||
|
||||
e = a; // ok
|
||||
a = e; // ok
|
||||
|
||||
if (typeof b !== 'object') {
|
||||
b.toString(); // error, never
|
||||
}
|
||||
|
||||
if (typeof b === 'object') {
|
||||
a = b; // error, b is not narrowed
|
||||
}
|
||||
|
||||
if (typeof d === 'object') {
|
||||
b = d; // ok
|
||||
d.toString(); // error, object | null
|
||||
} else {
|
||||
d.toString(); // error, undefined
|
||||
}
|
||||
|
||||
if (d == null) {
|
||||
d.toString(); // error, undefined | null
|
||||
} else {
|
||||
d.toString(); // object
|
||||
}
|
||||
|
||||
if (d === null) {
|
||||
d.toString(); // error, null
|
||||
} else {
|
||||
d.toString(); // error, object | undefined
|
||||
}
|
||||
|
||||
if (typeof d === 'undefined') {
|
||||
d.toString(); // error, undefined
|
||||
} else {
|
||||
d.toString(); // error, object | null
|
||||
}
|
||||
|
||||
interface Proxy<T extends object> {}
|
||||
|
||||
var x: Proxy<number>; // error
|
||||
var y: Proxy<null>; // error
|
||||
var z: Proxy<undefined>; // error
|
||||
|
||||
interface Blah {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
var u: Proxy<Blah>; // ok
|
||||
@@ -0,0 +1,5 @@
|
||||
// @declaration: true
|
||||
var a: object & string = ""; // error
|
||||
var b: object | string = ""; // ok
|
||||
a = b; // error
|
||||
b = a; // ok
|
||||
@@ -29,8 +29,15 @@ class Removable {
|
||||
removed: string;
|
||||
remainder: string;
|
||||
}
|
||||
interface I {
|
||||
m(): void;
|
||||
removed: string;
|
||||
remainder: string;
|
||||
}
|
||||
var removable = new Removable();
|
||||
var { removed, ...removableRest } = removable;
|
||||
var i: I = removable;
|
||||
var { removed, ...removableRest2 } = i;
|
||||
|
||||
let computed = 'b';
|
||||
let computed2 = 'a';
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
class K { p = 12; m() { } }
|
||||
interface I { p: number, m(): void }
|
||||
let k = new K()
|
||||
let sk = { ...k };
|
||||
let ssk = { ...k, ...k };
|
||||
sk.p;
|
||||
sk.m(); // error
|
||||
ssk.p;
|
||||
ssk.m(); // error
|
||||
let i: I = { p: 12, m() { } };
|
||||
let si = { ...i };
|
||||
let ssi = { ...i, ...i };
|
||||
si.p;
|
||||
si.m(); // ok
|
||||
ssi.p;
|
||||
ssi.m(); // ok
|
||||
let o = { p: 12, m() { } };
|
||||
let so = { ...o };
|
||||
let sso = { ...o, ...o };
|
||||
so.p;
|
||||
so.m(); // ok
|
||||
sso.p;
|
||||
sso.m(); // ok
|
||||
@@ -3,4 +3,5 @@ type any = I;
|
||||
type number = I;
|
||||
type boolean = I;
|
||||
type string = I;
|
||||
type void = I;
|
||||
type void = I;
|
||||
type object = I;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
class A<T> {
|
||||
constructor(private a: string) { }
|
||||
}
|
||||
|
||||
class B<T> {
|
||||
}
|
||||
|
||||
function acceptA<T>(a: A<T>) { }
|
||||
function acceptB<T>(b: B<T>) { }
|
||||
|
||||
function test<T>(x: A<T> | B<T>) {
|
||||
if (x instanceof B) {
|
||||
acceptA(x);
|
||||
}
|
||||
|
||||
if (x instanceof A) {
|
||||
acceptA(x);
|
||||
}
|
||||
|
||||
if (x instanceof B) {
|
||||
acceptB(x);
|
||||
}
|
||||
|
||||
if (x instanceof B) {
|
||||
acceptB(x);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: declarations.d.ts
|
||||
/////*module*/declare module "jquery"
|
||||
////declare module /*module*/"jquery"
|
||||
|
||||
// @Filename: user.ts
|
||||
///////<reference path="declarations.d.ts"/>
|
||||
////import /*importFoo*/foo, {bar} from "jquery";
|
||||
////import /*importBaz*/* as /*idBaz*/baz from "jquery";
|
||||
/////*importBang*/import /*idBang*/bang = require("jquery");
|
||||
////import * as /*importBaz*/baz from "jquery";
|
||||
////import /*importBang*/bang = require("jquery");
|
||||
////foo/*useFoo*/(bar/*useBar*/, baz/*useBaz*/, bang/*useBang*/);
|
||||
|
||||
verify.quickInfoAt("useFoo", "import foo");
|
||||
@@ -22,11 +22,11 @@ verify.goToDefinition("useBar", "module");
|
||||
verify.quickInfoAt("useBaz", "import baz");
|
||||
verify.goToDefinition({
|
||||
useBaz: "importBaz",
|
||||
idBaz: "module"
|
||||
importBaz: "module"
|
||||
});
|
||||
|
||||
verify.quickInfoAt("useBang", "import bang = require(\"jquery\")");
|
||||
verify.goToDefinition({
|
||||
useBang: "importBang",
|
||||
idBang: "module"
|
||||
importBang: "module"
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {}
|
||||
//// [|/* */ class /* */ C /* */ extends /* */ I|]{}
|
||||
|
||||
verify.rangeAfterCodeFix("/* */ class /* */ C /* */ implements /* */ I");
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 { }
|
||||
//// interface I2 { }
|
||||
|
||||
//// [|abstract class A extends I1 implements I2|] { }
|
||||
|
||||
verify.rangeAfterCodeFix("abstract class A implements I1, I2");
|
||||
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////interface I<X> { x: X}
|
||||
////[|class C<T extends string , U> extends I<T>|]{}
|
||||
|
||||
verify.rangeAfterCodeFix("class C<T extends string , U> implements I<T>");
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 { }
|
||||
//// interface I2 { }
|
||||
|
||||
//// function sealed(constructor: Function) {
|
||||
//// Object.seal(constructor);
|
||||
//// Object.seal(constructor.prototype);
|
||||
//// }
|
||||
|
||||
//// @sealed
|
||||
//// [|class A extends I1 implements I2 { }|]
|
||||
verify.rangeAfterCodeFix("class A implements I1, I2 { }");
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// f() {}
|
||||
//// }
|
||||
////
|
||||
//// let B = class implements A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
f(): void{
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// function foo<T>(a: T) {
|
||||
//// abstract class C<U> {
|
||||
//// abstract a: T | U;
|
||||
//// }
|
||||
//// return C;
|
||||
//// }
|
||||
////
|
||||
//// let B = class extends foo("s")<number> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
a: string | number;
|
||||
`);
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// function foo<T>(a: T) {
|
||||
//// abstract class C<U> {
|
||||
//// abstract a: T | U;
|
||||
//// }
|
||||
//// return C;
|
||||
//// }
|
||||
////
|
||||
//// class B extends foo("s")<number> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
a: string | number;
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract get b(): number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
b: number;
|
||||
`);
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// private _a: string;
|
||||
////
|
||||
//// abstract get a(): string;
|
||||
//// abstract set a(newName: string);
|
||||
//// }
|
||||
////
|
||||
//// // Don't need to add anything in this case.
|
||||
//// abstract class B extends A {}
|
||||
////
|
||||
//// class C extends A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
a: string;
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract f(a: number, b: string): boolean;
|
||||
//// abstract f(a: string, b: number): Function;
|
||||
//// abstract f(a: string): Function;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
f(a: number, b: string): boolean;
|
||||
f(a: string, b: number): Function;
|
||||
f(a: string): Function;
|
||||
f(a: any, b?: any) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A<T> {
|
||||
//// abstract f(x: T): T;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A<number> {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`f(x: number): number{
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A<T> {
|
||||
//// abstract f(x: T): T;
|
||||
//// }
|
||||
////
|
||||
//// class C<U> extends A<U> {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`f(x: U): U{
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// private abstract x: number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[|
|
||||
//// |]}
|
||||
|
||||
// We don't know how to fix this problem. We can:
|
||||
// 1) Make x protected, and then insert.
|
||||
// 2) Make x private, and then insert.
|
||||
// 3) Make x not abstract.
|
||||
// So we offer no fixes.
|
||||
verify.not.codeFixAvailable();
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract x: number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
`);
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// protected abstract x: number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
protected x: number;
|
||||
`);
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// public abstract x: number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
public x: number;
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract set c(arg: number | string);
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
c: string | number;
|
||||
`);
|
||||
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract x: number;
|
||||
//// abstract y: number;
|
||||
//// abstract z: number;
|
||||
//// }
|
||||
////
|
||||
//// class C extends A {[| |]
|
||||
//// constructor(public x: number) { super(); }
|
||||
//// y: number;
|
||||
//// }
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
z: number;
|
||||
`);
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <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);
|
||||
//// }
|
||||
////
|
||||
//// class C implements A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
a: string;
|
||||
b: number;
|
||||
c: string | number;
|
||||
`);
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// f() {}
|
||||
//// }
|
||||
////
|
||||
//// class B implements A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
f(): void{
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class C1 {
|
||||
//// f1() {}
|
||||
//// }
|
||||
////
|
||||
//// class C2 extends C1 {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// class C3 implements C2 {[|
|
||||
//// |]f2(){}
|
||||
//// }
|
||||
|
||||
verify.rangeAfterCodeFix(`f1(): void{
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// method(a: number, b: string): boolean;
|
||||
//// method(a: string | number, b?: string | number): boolean | Function { return true; }
|
||||
////
|
||||
//// class C implements A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
method(a: number, b: string): boolean;
|
||||
method(a: string | number, b?: string | number): boolean | Function {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// method(a: any, b: string): boolean;
|
||||
//// method(a: string, b: number): Function;
|
||||
//// method(a: string): Function;
|
||||
//// method(a: string | number, b?: string | number): boolean | Function { return true; }
|
||||
////
|
||||
//// class C implements A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
method(a: any, b: string): boolean;
|
||||
method(a: string, b: number): Function;
|
||||
method(a: string): Function;
|
||||
method(a: string | number, b?: string | number): boolean | Function {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class A {
|
||||
//// abstract x: number;
|
||||
//// private y: number;
|
||||
//// protected z: number;
|
||||
//// public w: number;
|
||||
//// }
|
||||
////
|
||||
//// class C implements A {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
protected z: number;
|
||||
public w: number;
|
||||
`);
|
||||
@@ -0,0 +1,63 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
|
||||
//// // Referenced throughout the inheritance chain.
|
||||
//// interface I0 { a: number }
|
||||
////
|
||||
//// class C1 implements I0 { a: number }
|
||||
//// interface I1 { b: number }
|
||||
//// interface I2 extends C1, I1 {}
|
||||
////
|
||||
//// class C2 { c: number }
|
||||
//// interface I3 {d: number}
|
||||
//// class C3 extends C2 implements I0, I2, I3 {
|
||||
//// a: number;
|
||||
//// b: number;
|
||||
//// d: number;
|
||||
//// }
|
||||
////
|
||||
//// interface I4 { e: number }
|
||||
//// interface I5 { f: number }
|
||||
//// class C4 extends C3 implements I0, I4, I5 {
|
||||
//// e: number;
|
||||
//// f: number;
|
||||
//// }
|
||||
////
|
||||
//// interface I6 extends C4 {}
|
||||
//// class C5 implements I6 {[|
|
||||
//// |]}
|
||||
|
||||
|
||||
/**
|
||||
* We want to check whether the search for member to replace actually searches through
|
||||
* the various possible paths of the inheritance chain correctly, and that We
|
||||
* don't issue duplicates for the same member.
|
||||
*
|
||||
* Our class DAG:
|
||||
*
|
||||
* C5
|
||||
* |-I6
|
||||
* |-C4
|
||||
* |-I4
|
||||
* |-I5
|
||||
* |------------------------ I0
|
||||
* |-C3
|
||||
* |-I2
|
||||
* |-I1
|
||||
* |-C1
|
||||
* |-------------------I0
|
||||
* |-I3
|
||||
* |-----------------------I0
|
||||
* |-C2
|
||||
*/
|
||||
|
||||
|
||||
verify.rangeAfterCodeFix(
|
||||
`
|
||||
e: number;
|
||||
f: number;
|
||||
a: number;
|
||||
b: number;
|
||||
d: number;
|
||||
c: number;
|
||||
`);
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I { x: number; }
|
||||
////
|
||||
//// export default class implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
`);
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// abstract class C1 {
|
||||
////
|
||||
//// }
|
||||
////
|
||||
//// abstract class C2 {
|
||||
//// abstract f1<T extends number>();
|
||||
//// }
|
||||
////
|
||||
//// interface I1 extends C1, C2 {}
|
||||
////
|
||||
//// class C3 implements I1 {[|
|
||||
////
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`f1<T extends number>(){
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// namespace N1 {
|
||||
//// export interface I1 {
|
||||
//// f1():string;
|
||||
//// }
|
||||
//// }
|
||||
//// interface I1 {
|
||||
//// f1();
|
||||
//// }
|
||||
////
|
||||
//// class C1 implements N1.I1 {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`f1(): string{
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
|
||||
//// interface I { x: number; }
|
||||
////
|
||||
//// new class implements I {[| |]};
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
`);
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// ["foo"](o: any): boolean;
|
||||
//// ["x"]: boolean;
|
||||
//// [1](): string;
|
||||
//// [2]: boolean;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
["foo"](o: any): boolean {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
["x"]: boolean;
|
||||
[1](): string {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[2]: boolean;
|
||||
`);
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @lib: es2017
|
||||
|
||||
//// interface I<Species> {
|
||||
//// [Symbol.hasInstance](o: any): boolean;
|
||||
//// [Symbol.isConcatSpreadable]: boolean;
|
||||
//// [Symbol.iterator](): any;
|
||||
//// [Symbol.match]: boolean;
|
||||
//// [Symbol.replace](...args);
|
||||
//// [Symbol.search](str: string): number;
|
||||
//// [Symbol.species](): Species;
|
||||
//// [Symbol.split](str: string, limit?: number): string[];
|
||||
//// [Symbol.toPrimitive](hint: "number"): number;
|
||||
//// [Symbol.toPrimitive](hint: "default"): number;
|
||||
//// [Symbol.toPrimitive](hint: "string"): string;
|
||||
//// [Symbol.toStringTag]: string;
|
||||
//// [Symbol.unscopables]: any;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I<number> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
[Symbol.hasInstance](o: any): boolean {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[Symbol.isConcatSpreadable]: boolean;
|
||||
[Symbol.iterator]() {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[Symbol.match]: boolean;
|
||||
[Symbol.replace](...args: {}) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[Symbol.search](str: string): number {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[Symbol.species](): number {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[Symbol.split](str: string, limit?: number): {} {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[Symbol.toPrimitive](hint: "number"): number;
|
||||
[Symbol.toPrimitive](hint: "default"): number;
|
||||
[Symbol.toPrimitive](hint: "string"): string;
|
||||
[Symbol.toPrimitive](hint: any) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
[Symbol.toStringTag]: string;
|
||||
[Symbol.unscopables]: any;
|
||||
`);
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 {
|
||||
//// x: number;
|
||||
//// }
|
||||
//// interface I2 {
|
||||
//// x: number;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I1,I2 {[|
|
||||
//// |]}
|
||||
|
||||
verify.codeFixAvailable();
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 {
|
||||
//// x: number;
|
||||
//// }
|
||||
//// interface I2 {
|
||||
//// x: number;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I1,I2 {
|
||||
//// x: number;
|
||||
//// }
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
|
||||
//// interface I {
|
||||
//// [x: number]: I;
|
||||
//// [y: string]: I;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
[x: number]: I;
|
||||
[y: string]: I;
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I4 {
|
||||
//// [x: string, y: number]: number;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// [x: number]: I;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
[x: number]: I;
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I<X> {
|
||||
//// [x: string]: X;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I<number> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
[x: string]: number;
|
||||
`);
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// f(x: number, y: string): I
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
f(x: number,y: string): I {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 {
|
||||
//// x: number;
|
||||
//// }
|
||||
//// interface I2 {
|
||||
//// y: number;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I1,I2 {[|
|
||||
//// y: number;
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
y: number;
|
||||
`);
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 {
|
||||
//// x: number;
|
||||
//// }
|
||||
//// interface I2 {
|
||||
//// y: number;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I1,I2 {[|
|
||||
//// x: number;
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
y: number;
|
||||
x: number;
|
||||
`);
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 {
|
||||
//// x: number;
|
||||
//// }
|
||||
//// interface I2 {
|
||||
//// x: string;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I1,I2 {[|
|
||||
//// |]}
|
||||
|
||||
verify.codeFixAvailable();
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 {
|
||||
//// x: number;
|
||||
//// }
|
||||
//// interface I2 {
|
||||
//// x: string;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I1,I2 {
|
||||
//// x: string;
|
||||
//// }
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
@@ -0,0 +1,28 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I1 {
|
||||
//// x: number,
|
||||
//// y: number
|
||||
//// z: number;
|
||||
//// f(),
|
||||
//// g()
|
||||
//// h();
|
||||
//// }
|
||||
////
|
||||
//// class C1 implements I1 {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
f() {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
g() {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
h() {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// method(a: number, b: string): boolean;
|
||||
//// method(a: string, b: number): Function;
|
||||
//// method(a: string): Function;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
method(a: number, b: string): boolean;
|
||||
method(a: string, b: number): Function;
|
||||
method(a: string): Function;
|
||||
method(a: any, b?: any) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// method(a: number, ...b: string[]): boolean;
|
||||
//// method(a: string, ...b: number[]): Function;
|
||||
//// method(a: string): Function;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
method(a: number, ...b: string[]): boolean;
|
||||
method(a: string, ...b: number[]): Function;
|
||||
method(a: string): Function;
|
||||
method(a: any, ...b?: any[]) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// method(a: number, ...b: string[]): boolean;
|
||||
//// method(a: string, b: number): Function;
|
||||
//// method(a: string): Function;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
method(a: number, ...b: string[]): boolean;
|
||||
method(a: string, b: number): Function;
|
||||
method(a: string): Function;
|
||||
method(a: any, b?: any, ...rest?: any[]) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
`);
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// namespace N1 {
|
||||
//// export interface I1 {
|
||||
//// x: number;
|
||||
//// }
|
||||
//// }
|
||||
//// interface I1 {
|
||||
//// f1();
|
||||
//// }
|
||||
////
|
||||
//// class C1 implements N1.I1 {[|
|
||||
//// |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
`);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// class A {
|
||||
//// constructor(public x: number) { }
|
||||
//// }
|
||||
////
|
||||
//// class B implements A {[| |]}
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
|
||||
// TODO: (arozga) Get this working.
|
||||
/*
|
||||
verify.rangeAfterCodeFix(`
|
||||
public x: number;
|
||||
`);
|
||||
*/
|
||||
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I {
|
||||
//// x: number;
|
||||
//// y: number;
|
||||
//// z: number & { __iBrand: any };
|
||||
//// }
|
||||
////
|
||||
//// class C implements I {[| |]
|
||||
//// constructor(public x: number) { }
|
||||
//// y: number;
|
||||
//// }
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
z: number & { __iBrand: any; };
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I<T> {
|
||||
//// x: { y: T, z: T[] };
|
||||
//// }
|
||||
////
|
||||
//// class C implements I<number> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: { y: number; z: number[]; };
|
||||
`);
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I<T extends string> {
|
||||
//// x: T;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I<number> { }
|
||||
|
||||
verify.codeFixAvailable();
|
||||
|
||||
// TODO: (arozga) Don't know how to instantiate in codeFix
|
||||
// if instantiation is invalid.
|
||||
// verify.not.codeFixAvailable();
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I<T> {
|
||||
//// x: T;
|
||||
//// }
|
||||
////
|
||||
//// class C implements I<number> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: number;
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I<T> {
|
||||
//// x: T;
|
||||
//// }
|
||||
////
|
||||
//// class C<T> implements I<T> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: T;
|
||||
`);
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// interface I<T> {
|
||||
//// x: T;
|
||||
//// }
|
||||
////
|
||||
//// class C<U> implements I<U> {[| |]}
|
||||
|
||||
verify.rangeAfterCodeFix(`
|
||||
x: U;
|
||||
`);
|
||||
Loaded 100 of 1383 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user