mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into import_star_namespace
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
// target: es5
|
||||
type MyType = {
|
||||
arguments: Array<string>
|
||||
}
|
||||
|
||||
declare function use(s: any);
|
||||
|
||||
function myFunction(myType: MyType) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
use(myType.arguments[i]);
|
||||
// create closure so that tsc will turn loop body into function
|
||||
const x = 5;
|
||||
[1, 2, 3].forEach(function(j) { use(x); })
|
||||
}
|
||||
}
|
||||
@@ -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,12 @@
|
||||
// @module: amd
|
||||
// @importHelpers: true
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/c/app.ts
|
||||
export let x = 1;
|
||||
|
||||
// @filename: /a/b/c/lib1.ts
|
||||
export let x = 1;
|
||||
|
||||
// @filename: /a/b/c/lib2.ts
|
||||
export let x = 1;
|
||||
@@ -0,0 +1,11 @@
|
||||
// @moduleResolution: node
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/node_modules/foo.d.ts
|
||||
export declare let x: number
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,11 @@
|
||||
// @moduleResolution: node
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/node_modules/foo.d.ts
|
||||
export declare let x: number
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,11 @@
|
||||
// @moduleResolution: classic
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/foo.d.ts
|
||||
export declare let x: number
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,11 @@
|
||||
// @moduleResolution: classic
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/foo.d.ts
|
||||
export declare let x: number
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,11 @@
|
||||
// @moduleResolution: node
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/node_modules/foo.d.ts
|
||||
export declare let x: number
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/lib.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,8 @@
|
||||
// @moduleResolution: node
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,8 @@
|
||||
// @moduleResolution: node
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,8 @@
|
||||
// @moduleResolution: classic
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,9 @@
|
||||
// @moduleResolution: classic
|
||||
// @traceResolution: true
|
||||
|
||||
// @filename: /a/b/c/lib.ts
|
||||
import {x} from "foo";
|
||||
|
||||
|
||||
// @filename: /a/b/c/d/e/app.ts
|
||||
import {x} from "foo";
|
||||
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
constructor(f: () => string) {
|
||||
}
|
||||
public blah(): string { return ""; }
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
super(() => { return super.blah(); })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @declaration: true
|
||||
|
||||
// @filename: db.d.ts
|
||||
declare namespace Db {
|
||||
export import Types = Db;
|
||||
}
|
||||
|
||||
export = Db;
|
||||
|
||||
// @filename: app.ts
|
||||
import * as Db from "./db"
|
||||
|
||||
export function foo() {
|
||||
return new Object()
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// @experimentalDecorators: true
|
||||
// @emitDecoratorMetadata: true
|
||||
// @target: es5
|
||||
|
||||
// @filename: aux.ts
|
||||
export class SomeClass {
|
||||
field: string;
|
||||
}
|
||||
|
||||
// @filename: aux1.ts
|
||||
export class SomeClass1 {
|
||||
field: string;
|
||||
}
|
||||
|
||||
// @filename: aux2.ts
|
||||
export class SomeClass2 {
|
||||
field: string;
|
||||
}
|
||||
// @filename: main.ts
|
||||
import { SomeClass } from './aux';
|
||||
import { SomeClass1 } from './aux1';
|
||||
|
||||
function annotation(): ClassDecorator {
|
||||
return (target: any): void => { };
|
||||
}
|
||||
|
||||
function annotation1(): MethodDecorator {
|
||||
return (target: any): void => { };
|
||||
}
|
||||
|
||||
@annotation()
|
||||
export class ClassA {
|
||||
array: SomeClass[];
|
||||
|
||||
constructor(...init: SomeClass[]) {
|
||||
this.array = init;
|
||||
}
|
||||
|
||||
@annotation1()
|
||||
foo(... args: SomeClass1[]) {
|
||||
}
|
||||
}
|
||||
@@ -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,9 @@
|
||||
// @target: ES3
|
||||
// @sourcemap: false
|
||||
// @declaration: false
|
||||
// @jsx: preserve
|
||||
|
||||
const React: any = null;
|
||||
|
||||
const elem = <div></div>;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// @target: ES3
|
||||
// @sourcemap: false
|
||||
// @declaration: false
|
||||
// @jsx: react-native
|
||||
|
||||
const React: any = null;
|
||||
|
||||
const elem = <div></div>;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// @target: ES3
|
||||
// @sourcemap: false
|
||||
// @declaration: false
|
||||
// @jsx: react
|
||||
|
||||
const React: any = null;
|
||||
|
||||
const elem = <div></div>;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target: ES3
|
||||
enum E {
|
||||
x = -01,
|
||||
y = 02,
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// @target: ES3
|
||||
let x: 010;
|
||||
let y: -020;
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target: ES5
|
||||
enum E {
|
||||
x = -01,
|
||||
y = 02,
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// @noImplicitAny: true
|
||||
({ a: [], ...(null as any) });
|
||||
let x: any;
|
||||
@@ -0,0 +1,9 @@
|
||||
// @importHelpers: true
|
||||
// @target: es5
|
||||
// @module: commonjs
|
||||
// @moduleResolution: classic
|
||||
// @filename: declaration.d.ts
|
||||
export declare class D {
|
||||
}
|
||||
export declare class E extends D {
|
||||
}
|
||||
@@ -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,23 @@
|
||||
//@jsx: preserve
|
||||
//@module: commonjs
|
||||
|
||||
//@filename: component.d.ts
|
||||
declare module JSX {
|
||||
interface ElementAttributesProperty { props; }
|
||||
}
|
||||
declare module React {
|
||||
class Component<T, U> { }
|
||||
}
|
||||
declare module "BaseComponent" {
|
||||
export default class extends React.Component<any, {}> {
|
||||
}
|
||||
}
|
||||
|
||||
//@filename: consumer.tsx
|
||||
/// <reference path="component.d.ts" />
|
||||
import BaseComponent from 'BaseComponent';
|
||||
class TestComponent extends React.Component<any, {}> {
|
||||
render() {
|
||||
return <BaseComponent />;
|
||||
}
|
||||
}
|
||||
@@ -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,21 @@
|
||||
// @filename: passport.d.ts
|
||||
declare module 'passport' {
|
||||
namespace passport {
|
||||
interface Passport {
|
||||
use(): this;
|
||||
}
|
||||
|
||||
interface PassportStatic extends Passport {
|
||||
Passport: {new(): Passport};
|
||||
}
|
||||
}
|
||||
|
||||
const passport: passport.PassportStatic;
|
||||
export = passport;
|
||||
}
|
||||
|
||||
//@filename: test.ts
|
||||
import * as passport from "passport";
|
||||
import { Passport } from "passport";
|
||||
|
||||
let p: Passport = passport.use();
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// @experimentalDecorators: true
|
||||
// @emitDecoratorMetadata: true
|
||||
// @target: es5
|
||||
// @includeBuiltFile: lib.d.ts
|
||||
|
||||
// @filename: event.ts
|
||||
export interface Event { title: string };
|
||||
|
||||
// @filename: test.ts
|
||||
import { Event } from './event';
|
||||
function Input(target: any, key: string): void { }
|
||||
export class SomeClass {
|
||||
@Input event: Event;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// @experimentalDecorators: true
|
||||
// @emitDecoratorMetadata: true
|
||||
function PropDeco(target: Object, propKey: string | symbol) { }
|
||||
|
||||
class A {
|
||||
}
|
||||
|
||||
class B {
|
||||
@PropDeco
|
||||
x: "foo" | null;
|
||||
|
||||
@PropDeco
|
||||
y: true | never;
|
||||
|
||||
@PropDeco
|
||||
z: "foo" | undefined;
|
||||
|
||||
@PropDeco
|
||||
a: null;
|
||||
|
||||
@PropDeco
|
||||
b: never;
|
||||
|
||||
@PropDeco
|
||||
c: undefined;
|
||||
|
||||
@PropDeco
|
||||
d: undefined | null;
|
||||
|
||||
@PropDeco
|
||||
e: symbol | null;
|
||||
|
||||
@PropDeco
|
||||
f: symbol | A;
|
||||
|
||||
@PropDeco
|
||||
g: A | null;
|
||||
|
||||
@PropDeco
|
||||
h: null | B;
|
||||
|
||||
@PropDeco
|
||||
j: null | symbol;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// This tests that a package.json "main" with an unexpected extension is ignored.
|
||||
|
||||
// @Filename: /node_modules/normalize.css/normalize.css
|
||||
This file is not read.
|
||||
|
||||
// @Filename: /node_modules/normalize.css/package.json
|
||||
{ "main": "normalize.css" }
|
||||
|
||||
// @Filename: /a.ts
|
||||
import "normalize.css";
|
||||
@@ -0,0 +1,12 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
// This tests that a package.json "types" with an unexpected extension is ignored.
|
||||
|
||||
// @Filename: /node_modules/foo/foo.js
|
||||
This file is not read.
|
||||
|
||||
// @Filename: /node_modules/foo/package.json
|
||||
{ "types": "foo.js" }
|
||||
|
||||
// @Filename: /a.ts
|
||||
import "foo";
|
||||
@@ -0,0 +1,14 @@
|
||||
// @strictNullChecks: true
|
||||
interface CSSProps {
|
||||
color?: string
|
||||
}
|
||||
interface NestedCSSProps {
|
||||
nested?: NestedSelector
|
||||
}
|
||||
interface NestedSelector {
|
||||
prop: CSSProps;
|
||||
}
|
||||
|
||||
let stylen: NestedCSSProps = {
|
||||
nested: { prop: { colour: 'red' } }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// @target: es5
|
||||
export class Test {
|
||||
constructor() {
|
||||
|
||||
let outerArray: Array<number> = [1, 2, 3];
|
||||
let innerArray: Array<number> = [1, 2, 3];
|
||||
|
||||
for (let outer of outerArray)
|
||||
for (let inner of innerArray) {
|
||||
this.aFunction((newValue, oldValue) => {
|
||||
let x = outer + inner + newValue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public aFunction(func: (newValue: any, oldValue: any) => void): void {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// @target: es5
|
||||
function baz(x: any) {
|
||||
return [[x, x]];
|
||||
}
|
||||
|
||||
function foo(set: any) {
|
||||
for (const [value, i] of baz(set.values)) {
|
||||
const bar: any = [];
|
||||
(() => bar);
|
||||
|
||||
set.values.push(...[]);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
// @outFile: out.js
|
||||
// @module: system
|
||||
// @moduleResolution: node
|
||||
// @noImplicitReferences: true
|
||||
|
||||
// @fileName: /node_modules/projB/index.ts
|
||||
export class C {}
|
||||
|
||||
// @fileName: /a.ts
|
||||
import { C } from "projB";
|
||||
@@ -0,0 +1,5 @@
|
||||
// @noImplicitAny: true
|
||||
let additional = [];
|
||||
for (const subcomponent of [1, 2, 3]) {
|
||||
additional = [...additional, subcomponent];
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
interface A {
|
||||
name();
|
||||
prop();
|
||||
}
|
||||
class B {
|
||||
public name() { }
|
||||
public prop() { }
|
||||
}
|
||||
class C {
|
||||
public static name() { }
|
||||
public static prop() { }
|
||||
}
|
||||
|
||||
var a: A = new B();
|
||||
a = new C(); // error name is missing
|
||||
a = B; // error name is missing
|
||||
a = new C(); // error prop is missing
|
||||
a = B; // error prop is missing
|
||||
a = C;
|
||||
|
||||
var b: B = new C(); // error name is missing
|
||||
b = B; // error name is missing
|
||||
var b: B = new C(); // error prop is missing
|
||||
b = B; // error prop is missing
|
||||
b = C;
|
||||
b = a;
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class Base {
|
||||
protected constructor() { }
|
||||
public instance1 = new Base(); // allowed
|
||||
}
|
||||
|
||||
class Subclass extends Base {
|
||||
public instance1_1 = new Base(); // allowed
|
||||
public instance1_2 = new Subclass(); // allowed
|
||||
}
|
||||
|
||||
class SubclassOfSubclass extends Subclass {
|
||||
public instance2_1 = new Base(); // allowed
|
||||
public instance2_2 = new Subclass(); // allowed
|
||||
public instance2_3 = new SubclassOfSubclass(); // allowed
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
constructor(f: string) {
|
||||
}
|
||||
public blah(): string { return ""; }
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
super(super.blah())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// @module: system
|
||||
export const test = "TEST";
|
||||
|
||||
//some comment
|
||||
@@ -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,14 @@
|
||||
// @noImplicitReferences: true
|
||||
// This tests that augmenting an untyped module is forbidden even in an ambient context. Contrast with `moduleAugmentationInDependency.ts`.
|
||||
|
||||
// @Filename: /node_modules/augmenter/index.d.ts
|
||||
declare module "js" {
|
||||
export const j: number;
|
||||
}
|
||||
export {};
|
||||
|
||||
// @Filename: /node_modules/js/index.js
|
||||
This file is not processed.
|
||||
|
||||
// @Filename: /a.ts
|
||||
import { } from "augmenter";
|
||||
@@ -0,0 +1,31 @@
|
||||
//@noUnusedLocals:true
|
||||
|
||||
declare var console: { log(a: any): void };
|
||||
|
||||
function one() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// 'a' is declared but never used
|
||||
const {a, ...bar} = foo;
|
||||
console.log(bar);
|
||||
}
|
||||
|
||||
function two() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// '_' is declared but never used
|
||||
const {a: _, ...bar} = foo;
|
||||
console.log(bar);
|
||||
}
|
||||
|
||||
function three() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// 'a' is declared but never used
|
||||
const {a, ...bar} = foo; // bar should be unused
|
||||
//console.log(bar);
|
||||
}
|
||||
|
||||
function four() {
|
||||
const foo = { a: 1, b: 2 };
|
||||
// '_' is declared but never used
|
||||
const {a: _, ...bar} = foo; // bar should be unused
|
||||
//console.log(bar);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: es2017
|
||||
// @strictNullChecks: true
|
||||
interface A extends Promise<string> {}
|
||||
declare var a: A;
|
||||
async function f() {
|
||||
await a;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class B {
|
||||
constructor(x?: string) {}
|
||||
x(): string { return ""; }
|
||||
}
|
||||
class C1 extends B {
|
||||
constructor() {
|
||||
super.x();
|
||||
super();
|
||||
}
|
||||
}
|
||||
class C2 extends B {
|
||||
constructor() {
|
||||
super(super.x());
|
||||
}
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
// @target: es5
|
||||
// name
|
||||
class StaticName {
|
||||
static name: number; // error
|
||||
name: string; // ok
|
||||
}
|
||||
|
||||
class StaticNameFn {
|
||||
static name() {} // error
|
||||
name() {} // ok
|
||||
}
|
||||
|
||||
// length
|
||||
class StaticLength {
|
||||
static length: number; // error
|
||||
length: string; // ok
|
||||
}
|
||||
|
||||
class StaticLengthFn {
|
||||
static length() {} // error
|
||||
length() {} // ok
|
||||
}
|
||||
|
||||
// prototype
|
||||
class StaticPrototype {
|
||||
static prototype: number; // error
|
||||
prototype: string; // ok
|
||||
}
|
||||
|
||||
class StaticPrototypeFn {
|
||||
static prototype() {} // error
|
||||
prototype() {} // ok
|
||||
}
|
||||
|
||||
// caller
|
||||
class StaticCaller {
|
||||
static caller: number; // error
|
||||
caller: string; // ok
|
||||
}
|
||||
|
||||
class StaticCallerFn {
|
||||
static caller() {} // error
|
||||
caller() {} // ok
|
||||
}
|
||||
|
||||
// arguments
|
||||
class StaticArguments {
|
||||
static arguments: number; // error
|
||||
arguments: string; // ok
|
||||
}
|
||||
|
||||
class StaticArgumentsFn {
|
||||
static arguments() {} // error
|
||||
arguments() {} // ok
|
||||
}
|
||||
|
||||
|
||||
|
||||
// === Static properties on anonymous classes ===
|
||||
|
||||
// name
|
||||
var StaticName_Anonymous = class {
|
||||
static name: number; // error
|
||||
name: string; // ok
|
||||
}
|
||||
|
||||
var StaticNameFn_Anonymous = class {
|
||||
static name() {} // error
|
||||
name() {} // ok
|
||||
}
|
||||
|
||||
// length
|
||||
var StaticLength_Anonymous = class {
|
||||
static length: number; // error
|
||||
length: string; // ok
|
||||
}
|
||||
|
||||
var StaticLengthFn_Anonymous = class {
|
||||
static length() {} // error
|
||||
length() {} // ok
|
||||
}
|
||||
|
||||
// prototype
|
||||
var StaticPrototype_Anonymous = class {
|
||||
static prototype: number; // error
|
||||
prototype: string; // ok
|
||||
}
|
||||
|
||||
var StaticPrototypeFn_Anonymous = class {
|
||||
static prototype() {} // error
|
||||
prototype() {} // ok
|
||||
}
|
||||
|
||||
// caller
|
||||
var StaticCaller_Anonymous = class {
|
||||
static caller: number; // error
|
||||
caller: string; // ok
|
||||
}
|
||||
|
||||
var StaticCallerFn_Anonymous = class {
|
||||
static caller() {} // error
|
||||
caller() {} // ok
|
||||
}
|
||||
|
||||
// arguments
|
||||
var StaticArguments_Anonymous = class {
|
||||
static arguments: number; // error
|
||||
arguments: string; // ok
|
||||
}
|
||||
|
||||
var StaticArgumentsFn_Anonymous = class {
|
||||
static arguments() {} // error
|
||||
arguments() {} // ok
|
||||
}
|
||||
|
||||
|
||||
// === Static properties on default exported classes ===
|
||||
|
||||
// name
|
||||
module TestOnDefaultExportedClass_1 {
|
||||
class StaticName {
|
||||
static name: number; // error
|
||||
name: string; // ok
|
||||
}
|
||||
}
|
||||
|
||||
module TestOnDefaultExportedClass_2 {
|
||||
class StaticNameFn {
|
||||
static name() {} // error
|
||||
name() {} // ok
|
||||
}
|
||||
}
|
||||
|
||||
// length
|
||||
module TestOnDefaultExportedClass_3 {
|
||||
export default class StaticLength {
|
||||
static length: number; // error
|
||||
length: string; // ok
|
||||
}
|
||||
}
|
||||
|
||||
module TestOnDefaultExportedClass_4 {
|
||||
export default class StaticLengthFn {
|
||||
static length() {} // error
|
||||
length() {} // ok
|
||||
}
|
||||
}
|
||||
|
||||
// prototype
|
||||
module TestOnDefaultExportedClass_5 {
|
||||
export default class StaticPrototype {
|
||||
static prototype: number; // error
|
||||
prototype: string; // ok
|
||||
}
|
||||
}
|
||||
|
||||
module TestOnDefaultExportedClass_6 {
|
||||
export default class StaticPrototypeFn {
|
||||
static prototype() {} // error
|
||||
prototype() {} // ok
|
||||
}
|
||||
}
|
||||
|
||||
// caller
|
||||
module TestOnDefaultExportedClass_7 {
|
||||
export default class StaticCaller {
|
||||
static caller: number; // error
|
||||
caller: string; // ok
|
||||
}
|
||||
}
|
||||
|
||||
module TestOnDefaultExportedClass_8 {
|
||||
export default class StaticCallerFn {
|
||||
static caller() {} // error
|
||||
caller() {} // ok
|
||||
}
|
||||
}
|
||||
|
||||
// arguments
|
||||
module TestOnDefaultExportedClass_9 {
|
||||
export default class StaticArguments {
|
||||
static arguments: number; // error
|
||||
arguments: string; // ok
|
||||
}
|
||||
}
|
||||
|
||||
module TestOnDefaultExportedClass_10 {
|
||||
export default class StaticArgumentsFn {
|
||||
static arguments() {} // error
|
||||
arguments() {} // ok
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
|
||||
//@Filename: decl.d.ts
|
||||
// name
|
||||
declare class StaticName {
|
||||
static name: number; // ok
|
||||
name: string; // ok
|
||||
}
|
||||
|
||||
declare class StaticNameFn {
|
||||
static name(): string; // ok
|
||||
name(): string; // ok
|
||||
}
|
||||
|
||||
// length
|
||||
declare class StaticLength {
|
||||
static length: number; // ok
|
||||
length: string; // ok
|
||||
}
|
||||
|
||||
declare class StaticLengthFn {
|
||||
static length(): number; // ok
|
||||
length(): number; // ok
|
||||
}
|
||||
|
||||
// prototype
|
||||
declare class StaticPrototype {
|
||||
static prototype: number; // ok
|
||||
prototype: string; // ok
|
||||
}
|
||||
|
||||
declare class StaticPrototypeFn {
|
||||
static prototype: any; // ok
|
||||
prototype(): any; // ok
|
||||
}
|
||||
|
||||
// caller
|
||||
declare class StaticCaller {
|
||||
static caller: number; // ok
|
||||
caller: string; // ok
|
||||
}
|
||||
|
||||
declare class StaticCallerFn {
|
||||
static caller(): any; // ok
|
||||
caller(): any; // ok
|
||||
}
|
||||
|
||||
// arguments
|
||||
declare class StaticArguments {
|
||||
static arguments: number; // ok
|
||||
arguments: string; // ok
|
||||
}
|
||||
|
||||
declare class StaticArgumentsFn {
|
||||
static arguments(): any; // ok
|
||||
arguments(): any; // ok
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// @target:es5
|
||||
// @experimentaldecorators: true
|
||||
declare function dec1<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
|
||||
declare function dec2<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
|
||||
|
||||
class A {
|
||||
@dec1 get x() { return 0; }
|
||||
set x(value: number) { }
|
||||
}
|
||||
|
||||
class B {
|
||||
get x() { return 0; }
|
||||
@dec2 set x(value: number) { }
|
||||
}
|
||||
|
||||
class C {
|
||||
@dec1 set x(value: number) { }
|
||||
get x() { return 0; }
|
||||
}
|
||||
|
||||
class D {
|
||||
set x(value: number) { }
|
||||
@dec2 get x() { return 0; }
|
||||
}
|
||||
|
||||
class E {
|
||||
@dec1 get x() { return 0; }
|
||||
@dec2 set x(value: number) { }
|
||||
}
|
||||
|
||||
class F {
|
||||
@dec1 set x(value: number) { }
|
||||
@dec2 get x() { return 0; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// @target:es5
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
declare function dec<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T>;
|
||||
|
||||
class A {
|
||||
@dec get x() { return 0; }
|
||||
set x(value: number) { }
|
||||
}
|
||||
|
||||
class B {
|
||||
get x() { return 0; }
|
||||
@dec set x(value: number) { }
|
||||
}
|
||||
|
||||
class C {
|
||||
@dec set x(value: number) { }
|
||||
get x() { return 0; }
|
||||
}
|
||||
|
||||
class D {
|
||||
set x(value: number) { }
|
||||
@dec get x() { return 0; }
|
||||
}
|
||||
|
||||
class E {
|
||||
@dec get x() { return 0; }
|
||||
}
|
||||
|
||||
class F {
|
||||
@dec set x(value: number) { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// @target: es5
|
||||
// @module: commonjs
|
||||
// @experimentaldecorators: true
|
||||
// @emitdecoratormetadata: true
|
||||
declare var dec: any;
|
||||
|
||||
@dec
|
||||
class A {
|
||||
}
|
||||
|
||||
@dec
|
||||
class B {
|
||||
constructor(x: number) {}
|
||||
}
|
||||
|
||||
@dec
|
||||
class C extends A {
|
||||
}
|
||||
+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)();
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface Flags { [name: string]: boolean };
|
||||
let flags: Flags;
|
||||
flags.b;
|
||||
flags.f;
|
||||
flags.isNotNecessarilyNeverFalse;
|
||||
flags['this is fine'];
|
||||
|
||||
interface Empty { }
|
||||
let empty: Empty;
|
||||
empty.nope;
|
||||
empty["that's ok"];
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// @noImplicitAny: true
|
||||
interface Flags { [name: string]: boolean }
|
||||
let flags: Flags;
|
||||
flags.b;
|
||||
flags.f;
|
||||
flags.isNotNecessarilyNeverFalse;
|
||||
flags['this is fine'];
|
||||
|
||||
interface Empty { }
|
||||
let empty: Empty;
|
||||
empty.nope;
|
||||
empty["not allowed either"];
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
type T1 = { a: number };
|
||||
type T2 = T1 & { b: number };
|
||||
type T3 = () => void;
|
||||
type T4 = new () => { a: number };
|
||||
type T5 = number[];
|
||||
type T6 = [string, number];
|
||||
type T7 = { [P in 'a' | 'b' | 'c']: string };
|
||||
|
||||
interface I1 extends T1 { x: string }
|
||||
interface I2 extends T2 { x: string }
|
||||
interface I3 extends T3 { x: string }
|
||||
interface I4 extends T4 { x: string }
|
||||
interface I5 extends T5 { x: string }
|
||||
interface I6 extends T6 { x: string }
|
||||
interface I7 extends T7 { x: string }
|
||||
|
||||
type Constructor<T> = new () => T;
|
||||
declare function Constructor<T>(): Constructor<T>;
|
||||
|
||||
class C1 extends Constructor<I1>() { x: string }
|
||||
class C2 extends Constructor<I2>() { x: string }
|
||||
class C3 extends Constructor<I3>() { x: string }
|
||||
class C4 extends Constructor<I4>() { x: string }
|
||||
class C5 extends Constructor<I5>() { x: string }
|
||||
class C6 extends Constructor<I6>() { x: string }
|
||||
class C7 extends Constructor<I7>() { x: string }
|
||||
|
||||
declare function fx(x: string): string;
|
||||
declare class CX { a: number }
|
||||
declare enum EX { A, B, C }
|
||||
declare namespace NX { export const a = 1 }
|
||||
|
||||
type T10 = typeof fx;
|
||||
type T11 = typeof CX;
|
||||
type T12 = typeof EX;
|
||||
type T13 = typeof NX;
|
||||
|
||||
interface I10 extends T10 { x: string }
|
||||
interface I11 extends T11 { x: string }
|
||||
interface I12 extends T12 { x: string }
|
||||
interface I13 extends T13 { x: string }
|
||||
|
||||
type Identifiable<T> = { _id: string } & T;
|
||||
|
||||
interface I20 extends Partial<T1> { x: string }
|
||||
interface I21 extends Readonly<T1> { x: string }
|
||||
interface I22 extends Identifiable<T1> { x: string }
|
||||
interface I23 extends Identifiable<T1 & { b: number}> { x: string }
|
||||
|
||||
class C20 extends Constructor<Partial<T1>>() { x: string }
|
||||
class C21 extends Constructor<Readonly<T1>>() { x: string }
|
||||
class C22 extends Constructor<Identifiable<T1>>() { x: string }
|
||||
class C23 extends Constructor<Identifiable<T1 & { b: number}>>() { x: string }
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// @strictNullChecks: true
|
||||
|
||||
type T1 = { a: number };
|
||||
type T2 = T1 & { b: number };
|
||||
type T3 = number[];
|
||||
type T4 = [string, number];
|
||||
type T5 = { [P in 'a' | 'b' | 'c']: string };
|
||||
|
||||
interface I1 extends T1 { a: string }
|
||||
interface I2 extends T2 { b: string }
|
||||
interface I3 extends T3 { length: string }
|
||||
interface I4 extends T4 { 0: number }
|
||||
interface I5 extends T5 { c: number }
|
||||
|
||||
type Constructor<T> = new () => T;
|
||||
declare function Constructor<T>(): Constructor<T>;
|
||||
|
||||
class C1 extends Constructor<T1>() { a: string }
|
||||
class C2 extends Constructor<T2>() { b: string }
|
||||
class C3 extends Constructor<T3>() { length: string }
|
||||
class C4 extends Constructor<T4>() { 0: number }
|
||||
class C5 extends Constructor<T5>() { c: number }
|
||||
|
||||
declare class CX { static a: string }
|
||||
declare enum EX { A, B, C }
|
||||
declare namespace NX { export const a = "hello" }
|
||||
|
||||
type TCX = typeof CX;
|
||||
type TEX = typeof EX;
|
||||
type TNX = typeof NX;
|
||||
|
||||
interface I10 extends TCX { a: number }
|
||||
interface I11 extends TEX { C: string }
|
||||
interface I12 extends TNX { a: number }
|
||||
interface I14 extends TCX { [x: string]: number }
|
||||
interface I15 extends TEX { [x: string]: number }
|
||||
interface I16 extends TNX { [x: string]: number }
|
||||
|
||||
type Identifiable<T> = { _id: string } & T;
|
||||
|
||||
interface I20 extends Partial<T1> { a: string }
|
||||
interface I21 extends Readonly<T1> { a: string }
|
||||
interface I22 extends Identifiable<T1> { a: string }
|
||||
interface I23 extends Identifiable<T1 & { b: number}> { a: string }
|
||||
|
||||
type U = { a: number } | { b: string };
|
||||
|
||||
interface I30 extends U { x: string }
|
||||
interface I31<T> extends T { x: string }
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
interface Thing1 {
|
||||
a: number;
|
||||
self(): this;
|
||||
}
|
||||
|
||||
interface Thing2 {
|
||||
b: number;
|
||||
me(): this;
|
||||
}
|
||||
|
||||
type Thing3 = Thing1 & Thing2;
|
||||
type Thing4 = Thing3 & string[];
|
||||
|
||||
function f1(t: Thing3) {
|
||||
t = t.self();
|
||||
t = t.me().self().me();
|
||||
}
|
||||
|
||||
interface Thing5 extends Thing4 {
|
||||
c: string;
|
||||
}
|
||||
|
||||
function f2(t: Thing5) {
|
||||
t = t.self();
|
||||
t = t.me().self().me();
|
||||
}
|
||||
|
||||
interface Component {
|
||||
extend<T>(props: T): this & T;
|
||||
}
|
||||
|
||||
interface Label extends Component {
|
||||
title: string;
|
||||
}
|
||||
|
||||
function test(label: Label) {
|
||||
const extended = label.extend({ id: 67 }).extend({ tag: "hello" });
|
||||
extended.id; // Ok
|
||||
extended.tag; // Ok
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// @declaration: true
|
||||
|
||||
type T1 = {
|
||||
x: T1["x"]; // Error
|
||||
};
|
||||
|
||||
type T2<K extends "x" | "y"> = {
|
||||
x: T2<K>[K]; // Error
|
||||
y: number;
|
||||
}
|
||||
|
||||
declare let x2: T2<"x">;
|
||||
let x2x = x2.x;
|
||||
|
||||
interface T3<T extends T3<T>> {
|
||||
x: T["x"];
|
||||
}
|
||||
|
||||
interface T4<T extends T4<T>> {
|
||||
x: T4<T>["x"]; // Error
|
||||
}
|
||||
|
||||
class C1 {
|
||||
x: C1["x"]; // Error
|
||||
}
|
||||
|
||||
class C2 {
|
||||
x: this["y"];
|
||||
y: this["z"];
|
||||
z: this["x"];
|
||||
}
|
||||
|
||||
// Repro from #12627
|
||||
|
||||
interface Foo {
|
||||
hello: boolean;
|
||||
}
|
||||
|
||||
function foo<T extends Foo | T["hello"]>() {
|
||||
}
|
||||
@@ -250,6 +250,77 @@ function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[
|
||||
let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean
|
||||
}
|
||||
|
||||
function f80<T extends { a: { x: any } }>(obj: T) {
|
||||
let a1 = obj.a; // { x: any }
|
||||
let a2 = obj['a']; // { x: any }
|
||||
let a3 = obj['a'] as T['a']; // T["a"]
|
||||
let x1 = obj.a.x; // any
|
||||
let x2 = obj['a']['x']; // any
|
||||
let x3 = obj['a']['x'] as T['a']['x']; // T["a"]["x"]
|
||||
}
|
||||
|
||||
function f81<T extends { a: { x: any } }>(obj: T) {
|
||||
return obj['a']['x'] as T['a']['x'];
|
||||
}
|
||||
|
||||
function f82() {
|
||||
let x1 = f81({ a: { x: "hello" } }); // string
|
||||
let x2 = f81({ a: { x: 42 } }); // number
|
||||
}
|
||||
|
||||
function f83<T extends { [x: string]: { x: any } }, K extends keyof T>(obj: T, key: K) {
|
||||
return obj[key]['x'] as T[K]['x'];
|
||||
}
|
||||
|
||||
function f84() {
|
||||
let x1 = f83({ foo: { x: "hello" } }, "foo"); // string
|
||||
let x2 = f83({ bar: { x: 42 } }, "bar"); // number
|
||||
}
|
||||
|
||||
class C1 {
|
||||
x: number;
|
||||
get<K extends keyof this>(key: K) {
|
||||
return this[key];
|
||||
}
|
||||
set<K extends keyof this>(key: K, value: this[K]) {
|
||||
this[key] = value;
|
||||
}
|
||||
foo() {
|
||||
let x1 = this.x; // number
|
||||
let x2 = this["x"]; // number
|
||||
let x3 = this.get("x"); // this["x"]
|
||||
let x4 = getProperty(this, "x"); // this["x"]
|
||||
this.x = 42;
|
||||
this["x"] = 42;
|
||||
this.set("x", 42);
|
||||
setProperty(this, "x", 42);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -365,4 +436,84 @@ interface R {
|
||||
function f<K extends keyof R>(p: K) {
|
||||
let a: any;
|
||||
a[p].add; // any
|
||||
}
|
||||
}
|
||||
|
||||
// Repro from #12651
|
||||
|
||||
type MethodDescriptor = {
|
||||
name: string;
|
||||
args: any[];
|
||||
returnValue: any;
|
||||
}
|
||||
|
||||
declare function dispatchMethod<M extends MethodDescriptor>(name: M['name'], args: M['args']): M['returnValue'];
|
||||
|
||||
type SomeMethodDescriptor = {
|
||||
name: "someMethod";
|
||||
args: [string, number];
|
||||
returnValue: string[];
|
||||
}
|
||||
|
||||
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.
|
||||
}
|
||||
|
||||
// Repro from #13514
|
||||
|
||||
declare function head<T extends Array<any>>(list: T): T[0];
|
||||
|
||||
// Repro from #13604
|
||||
|
||||
class A<T> {
|
||||
props: T & { foo: string };
|
||||
}
|
||||
|
||||
class B extends A<{ x: number}> {
|
||||
f(p: this["props"]) {
|
||||
p.x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,4 +84,63 @@ function f21() {
|
||||
let x1 = objAndPartial({ x: 0, y: 0 }, { x: 1 });
|
||||
let x2 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1 });
|
||||
let x3 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error
|
||||
}
|
||||
}
|
||||
|
||||
// Verify use of Pick<T, K> for setState functions (#12793)
|
||||
|
||||
interface Foo {
|
||||
a: string;
|
||||
b?: number;
|
||||
}
|
||||
|
||||
function setState<T, K extends keyof T>(obj: T, props: Pick<T, K>) {
|
||||
for (let k in props) {
|
||||
obj[k] = props[k];
|
||||
}
|
||||
}
|
||||
|
||||
let foo: Foo = { a: "hello", b: 42 };
|
||||
setState(foo, { a: "test", b: 43 })
|
||||
setState(foo, { a: "hi" });
|
||||
setState(foo, { b: undefined });
|
||||
setState(foo, { });
|
||||
setState(foo, foo);
|
||||
setState(foo, { a: undefined }); // Error
|
||||
setState(foo, { c: true }); // Error
|
||||
|
||||
class C<T> {
|
||||
state: T;
|
||||
setState<K extends keyof T>(props: Pick<T, K>) {
|
||||
for (let k in props) {
|
||||
this.state[k] = props[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let c = new C<Foo>();
|
||||
c.setState({ a: "test", b: 43 });
|
||||
c.setState({ a: "hi" });
|
||||
c.setState({ b: undefined });
|
||||
c.setState({ });
|
||||
c.setState(foo);
|
||||
c.setState({ a: undefined }); // Error
|
||||
c.setState({ c: true }); // Error
|
||||
|
||||
type T2 = { a?: number, [key: string]: any };
|
||||
|
||||
let x1: T2 = { a: 'no' }; // Error
|
||||
let x2: Partial<T2> = { a: 'no' }; // Error
|
||||
let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error
|
||||
|
||||
// Repro from #13044
|
||||
|
||||
type Foo2<T, F extends keyof T> = {
|
||||
pf: {[P in F]?: T[P]},
|
||||
pt: {[P in T]?: T[P]}, // note: should be in keyof T
|
||||
};
|
||||
type O = {x: number, y: boolean};
|
||||
let o: O = {x: 5, y: false};
|
||||
let f: Foo2<O, 'x'> = {
|
||||
pf: {x: 7},
|
||||
pt: {x: 7, y: false},
|
||||
};
|
||||
|
||||
@@ -1,85 +1,100 @@
|
||||
// @strictNullChecks: true
|
||||
// @noimplicitany: true
|
||||
|
||||
type T = { a: number, b: string };
|
||||
type TU = { a: number | undefined, b: string | undefined };
|
||||
type TP = { a?: number, b?: string };
|
||||
type TR = { readonly a: number, readonly b: string };
|
||||
type TPR = { readonly a?: number, readonly b?: string };
|
||||
|
||||
// Validate they all have the same keys
|
||||
var v00: "a" | "b";
|
||||
var v00: keyof T;
|
||||
var v00: keyof TU;
|
||||
var v00: keyof TP;
|
||||
var v00: keyof TR;
|
||||
var v00: keyof TPR;
|
||||
|
||||
// Validate that non-isomorphic mapped types strip modifiers
|
||||
var v01: T;
|
||||
var v01: Pick<TR, keyof T>;
|
||||
var v01: Pick<Readonly<T>, keyof T>;
|
||||
var v01: { [P in keyof T]: T[P] };
|
||||
var v01: Pick<T, keyof T>;
|
||||
var v01: Pick<Pick<T, keyof T>, keyof T>;
|
||||
|
||||
// Validate that non-isomorphic mapped types strip modifiers
|
||||
var v02: TU;
|
||||
var v02: Pick<TP, keyof T>;
|
||||
var v02: Pick<TPR, keyof T>;
|
||||
var v02: Pick<Partial<T>, keyof T>;
|
||||
var v02: Pick<Partial<Readonly<T>>, keyof T>;
|
||||
var v02: TP;
|
||||
var v02: { [P in keyof T]?: T[P] };
|
||||
var v02: Partial<T>;
|
||||
var v02: { [P in keyof TP]: TP[P] }
|
||||
var v02: Pick<TP, keyof TP>;
|
||||
|
||||
// Validate that isomorphic mapped types preserve optional modifier
|
||||
var v03: TP;
|
||||
var v03: Partial<T>;
|
||||
var v03: TR;
|
||||
var v03: { readonly [P in keyof T]: T[P] };
|
||||
var v03: Readonly<T>;
|
||||
var v03: { [P in keyof TR]: TR[P] }
|
||||
var v03: Pick<TR, keyof TR>;
|
||||
|
||||
// Validate that isomorphic mapped types preserve readonly modifier
|
||||
var v04: TR;
|
||||
var v04: Readonly<T>;
|
||||
|
||||
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
|
||||
var v05: TPR;
|
||||
var v05: Partial<TR>;
|
||||
var v05: Readonly<TP>;
|
||||
var v05: Partial<Readonly<T>>;
|
||||
var v05: Readonly<Partial<T>>;
|
||||
var v04: TPR;
|
||||
var v04: { readonly [P in keyof T]?: T[P] };
|
||||
var v04: Partial<TR>;
|
||||
var v04: Readonly<TP>;
|
||||
var v04: Partial<Readonly<T>>;
|
||||
var v04: Readonly<Partial<T>>;
|
||||
var v04: { [P in keyof TPR]: TPR[P] }
|
||||
var v04: Pick<TPR, keyof T>;
|
||||
|
||||
type Boxified<T> = { [P in keyof T]: { x: T[P] } };
|
||||
|
||||
type B = { a: { x: number }, b: { x: string } };
|
||||
type BU = { a: { x: number } | undefined, b: { x: string } | undefined };
|
||||
type BP = { a?: { x: number }, b?: { x: string } };
|
||||
type BR = { readonly a: { x: number }, readonly b: { x: string } };
|
||||
type BPR = { readonly a?: { x: number }, readonly b?: { x: string } };
|
||||
|
||||
// Validate they all have the same keys
|
||||
var b00: "a" | "b";
|
||||
var b00: keyof B;
|
||||
var b00: keyof BU;
|
||||
var b00: keyof BP;
|
||||
var b00: keyof BR;
|
||||
var b00: keyof BPR;
|
||||
|
||||
// Validate that non-isomorphic mapped types strip modifiers
|
||||
var b01: B;
|
||||
var b01: Pick<BR, keyof B>;
|
||||
var b01: Pick<Readonly<BR>, keyof B>;
|
||||
var b01: { [P in keyof B]: B[P] };
|
||||
var b01: Pick<B, keyof B>;
|
||||
var b01: Pick<Pick<B, keyof B>, keyof B>;
|
||||
|
||||
// Validate that non-isomorphic mapped types strip modifiers
|
||||
var b02: BU;
|
||||
var b02: Pick<BP, keyof B>;
|
||||
var b02: Pick<BPR, keyof B>;
|
||||
var b02: Pick<Partial<B>, keyof B>;
|
||||
var b02: Pick<Partial<Readonly<B>>, keyof B>;
|
||||
var b02: BP;
|
||||
var b02: { [P in keyof B]?: B[P] };
|
||||
var b02: Partial<B>;
|
||||
var b02: { [P in keyof BP]: BP[P] }
|
||||
var b02: Pick<BP, keyof BP>;
|
||||
|
||||
// Validate that isomorphic mapped types preserve optional modifier
|
||||
var b03: BP;
|
||||
var b03: Partial<B>;
|
||||
var b03: BR;
|
||||
var b03: { readonly [P in keyof B]: B[P] };
|
||||
var b03: Readonly<B>;
|
||||
var b03: { [P in keyof BR]: BR[P] }
|
||||
var b03: Pick<BR, keyof BR>;
|
||||
|
||||
// Validate that isomorphic mapped types preserve readonly modifier
|
||||
var b04: BR;
|
||||
var b04: Readonly<B>;
|
||||
var b04: BPR;
|
||||
var b04: { readonly [P in keyof B]?: B[P] };
|
||||
var b04: Partial<BR>;
|
||||
var b04: Readonly<BP>;
|
||||
var b04: Partial<Readonly<B>>;
|
||||
var b04: Readonly<Partial<B>>;
|
||||
var b04: { [P in keyof BPR]: BPR[P] }
|
||||
var b04: Pick<BPR, keyof BPR>;
|
||||
|
||||
// Validate that isomorphic mapped types preserve both partial and readonly modifiers
|
||||
var b05: BPR;
|
||||
var b05: Partial<BR>;
|
||||
var b05: Readonly<BP>;
|
||||
var b05: Partial<Readonly<B>>;
|
||||
var b05: Readonly<Partial<B>>;
|
||||
type Foo = { prop: number, [x: string]: number };
|
||||
|
||||
function f1(x: Partial<Foo>) {
|
||||
x.prop; // ok
|
||||
(x["other"] || 0).toFixed();
|
||||
}
|
||||
|
||||
function f2(x: Readonly<Foo>) {
|
||||
x.prop; // ok
|
||||
x["other"].toFixed();
|
||||
}
|
||||
|
||||
function f3(x: Boxified<Foo>) {
|
||||
x.prop; // ok
|
||||
x["other"].x.toFixed();
|
||||
}
|
||||
|
||||
function f4(x: { [P in keyof Foo]: Foo[P] }) {
|
||||
x.prop; // ok
|
||||
x["other"].toFixed();
|
||||
}
|
||||
|
||||
@@ -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,35 @@
|
||||
// @strictNullChecks: true
|
||||
// @declaration: true
|
||||
|
||||
function f1<T>(x: Partial<T>, y: Readonly<T>) {
|
||||
let obj: {};
|
||||
obj = x;
|
||||
obj = y;
|
||||
}
|
||||
|
||||
function f2<T>(x: Partial<T>, y: Readonly<T>) {
|
||||
let obj: { [x: string]: any };
|
||||
obj = x;
|
||||
obj = y;
|
||||
}
|
||||
|
||||
// Repro from #12900
|
||||
|
||||
interface Base {
|
||||
foo: { [key: string]: any };
|
||||
bar: any;
|
||||
baz: any;
|
||||
}
|
||||
|
||||
interface E1<T> extends Base {
|
||||
foo: T;
|
||||
}
|
||||
|
||||
interface Something { name: string, value: string };
|
||||
interface E2 extends Base {
|
||||
foo: Partial<Something>; // or other mapped type
|
||||
}
|
||||
|
||||
interface E3<T> extends Base {
|
||||
foo: Partial<T>; // or other mapped type
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
var x = {};
|
||||
var y = {foo: "bar"};
|
||||
var a: object;
|
||||
a = x;
|
||||
a = y;
|
||||
@@ -0,0 +1,6 @@
|
||||
var a: object;
|
||||
a.toString();
|
||||
a.nonExist(); // error
|
||||
|
||||
var { destructuring } = a; // error
|
||||
var { ...rest } = a; // ok
|
||||
@@ -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,12 +29,19 @@ 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';
|
||||
var { [computed]: stillNotGreat, [computed2]: soSo, ...o } = o;
|
||||
({ [computed]: stillNotGreat, [computed2]: soSo, ...o } = o);
|
||||
|
||||
var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmptyObject['anythingGoes'];
|
||||
var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmptyObject.anythingGoes;
|
||||
|
||||
@@ -16,5 +16,3 @@ function generic<T extends { x, y }>(t: T) {
|
||||
|
||||
let rest: { b: string }
|
||||
({a, ...rest.b + rest.b} = o);
|
||||
|
||||
var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmptyObject.anythingGoes;
|
||||
|
||||
@@ -78,4 +78,5 @@ let computedAfter: { a: number, b: string, "at the end": number } =
|
||||
// shortcut syntax
|
||||
let a = 12;
|
||||
let shortCutted: { a: number, b: string } = { ...o, a }
|
||||
|
||||
// non primitive
|
||||
let spreadNonPrimitive = { ...<object>{}};
|
||||
|
||||
@@ -52,6 +52,11 @@ let c: C = new C()
|
||||
let spreadC = { ...c }
|
||||
spreadC.m(); // error 'm' is not in '{ ... c }'
|
||||
|
||||
// non primitive
|
||||
let obj: object = { a: 123 };
|
||||
let spreadObj = { ...obj };
|
||||
spreadObj.a; // error 'a' is not in {}
|
||||
|
||||
// generics
|
||||
function f<T, U>(t: T, u: U) {
|
||||
return { ...t, ...u, id: 'id' };
|
||||
|
||||
@@ -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"
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user