Merge branch 'master' into untyped_module_symbol

This commit is contained in:
Andy Hanson committed 2017-01-25 06:39:26 -08:00
commit acf317cb13
2256 files changed
+162805 -128283

No files matched your search

@@ -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); })
}
}
+2
View File
@@ -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]);
}
+12
View File
@@ -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,5 @@
function f (m: string) {
[1, 2, 3].map(i => {
return true? { [m]: i } : { [m]: i + 1 }
})
}
@@ -1,8 +1,10 @@
// @strictNullChecks: true
// @allowJs: true
// @Filename: controlFlowJavascript.js
// @out: out.js
declare let cond: boolean;
let cond = true;
// CFA for 'let' with no type annotation and initializer
// CFA for 'let' and no initializer
function f1() {
let x;
if (cond) {
@@ -14,7 +16,7 @@ function f1() {
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
// CFA for 'let' and 'undefined' initializer
function f2() {
let x = undefined;
if (cond) {
@@ -26,7 +28,7 @@ function f2() {
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
// CFA for 'let' and 'null' initializer
function f3() {
let x = null;
if (cond) {
@@ -38,19 +40,7 @@ function f3() {
const y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
let x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// CFA for 'var' with no type annotation and initializer
// CFA for 'var' with no initializer
function f5() {
var x;
if (cond) {
@@ -62,7 +52,7 @@ function f5() {
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
// CFA for 'var' with 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
@@ -74,7 +64,7 @@ function f6() {
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
// CFA for 'var' with 'null' initializer
function f7() {
var x = null;
if (cond) {
@@ -86,18 +76,6 @@ function f7() {
const y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// No CFA for captured outer variables
function f9() {
let x;
@@ -126,4 +104,4 @@ function f10() {
const f = () => {
const z = x; // any
};
}
}
@@ -0,0 +1,102 @@
// @noimplicitany: true
// Repro from #12319
function md5(string:string): void {
function FF(a,b,c,d,x,s,ac) {
return 0;
};
function GG(a,b,c,d,x,s,ac) {
return 0;
};
function HH(a,b,c,d,x,s,ac) {
return 0;
};
function II(a,b,c,d,x,s,ac) {
return 0;
};
var x=Array();
var k,AA,BB,CC,DD,a,b,c,d;
var S11=7, S12=12, S13=17, S14=22;
var S21=5, S22=9 , S23=14, S24=20;
var S31=4, S32=11, S33=16, S34=23;
var S41=6, S42=10, S43=15, S44=21;
x = [1];
a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
for (k=0;k<x.length;k+=16) {
AA=a; BB=b; CC=c; DD=d;
a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
d=GG(d,a,b,c,x[k+10],S22,0x2441453);
c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
a=II(a,b,c,d,x[k+0], S41,0xF4292244);
d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
c=II(c,d,a,b,x[k+6], S43,0xA3014314);
b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
}
}
export default md5;
@@ -0,0 +1,5 @@
// @declaration: true
export interface Test {
[index: TypeNotFound]: any;
}
@@ -0,0 +1,4 @@
// @declaration: true
class A { }
interface Class extends (typeof A) { }
@@ -0,0 +1,3 @@
// @declaration: true
type A<T extends Unknown> = {}
@@ -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,18 @@
// @noemithelpers: true
// @experimentaldecorators: true
declare var console : { log(arg: string): void };
function dec(): Function {
return function (target: any, propKey: string, descr: PropertyDescriptor): void {
console.log(target[propKey]);
//logs undefined
//propKey has three underscores as prefix, but the method has only two underscores
};
}
class A {
@dec()
private __foo(bar: string): void {
// do something with bar
}
}
+20
View File
@@ -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>;
+9
View File
@@ -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,18 @@
// @strictNullChecks: true
// Repro from #12529
class A {
readonly kind = "A"; // (property) A.kind: "A"
}
class B {
readonly kind = "B"; // (property) B.kind: "B"
}
function f(value: A | B): number {
switch(value.kind) {
case "A": return 0;
case "B": return 1;
}
}
@@ -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;
@@ -57,4 +57,49 @@ function getValueAsString(value: IntersectionFail): string {
return '' + value.num;
}
return value.str;
}
// Repro from #12535
namespace enums {
export const enum A {
a1,
a2,
a3,
// ... elements omitted for the sake of clarity
a75,
a76,
a77,
}
export const enum B {
b1,
b2,
// ... elements omitted for the sake of clarity
b86,
b87,
}
export const enum C {
c1,
c2,
// ... elements omitted for the sake of clarity
c210,
c211,
}
export type Genre = A | B | C;
}
type Foo = {
genreId: enums.Genre;
};
type Bar = {
genreId: enums.Genre;
};
type FooBar = Foo & Bar;
function foo(so: any) {
const val = so as FooBar;
const isGenre = val.genreId;
return isGenre;
}
@@ -0,0 +1,6 @@
type A = & string;
type B =
& { foo: string }
& { bar: number };
type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }];
@@ -0,0 +1,4 @@
interface OhNo {
}
declare let y: OhNo.hello;
@@ -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,17 @@
//@module: commonjs
//@target: es5
//@jsx: react
//@jsxFactory: skate.h
//@noEmit: false
// @filename: index.tsx
import "./jsx";
var skate: any;
const React = { createElement: skate.h };
class Component {
renderCallback() {
return <div>test</div>;
}
};
@@ -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>;
}
}) {}
+23
View File
@@ -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,13 @@
// keyof T is a literal contextual type
function foo<T extends { a: string, b: string }>() {
let a: (keyof T)[] = ["a", "b"];
let b: (keyof T)[] = ["a", "b", "c"];
}
// Repro from #12455
declare function pick<T, K extends keyof T>(obj: T, propNames: K[]): Pick<T, K>;
let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]);
let b = x.b; // Error
@@ -0,0 +1,7 @@
// Repro from #12511
type HTML = { [K in 'div']: Block<HTML> };
type Block<P> = <T>(func: HTML) => {};
declare var h: HTML;
h.div(h);
@@ -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' } }
}
+18
View File
@@ -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";
+12
View File
@@ -0,0 +1,12 @@
const f = Object.freeze(function foo(a: number, b: string) { return false; });
f(1, "") === false;
class C { constructor(a: number) { } }
const c = Object.freeze(C);
new c(1);
const a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();
const o = Object.freeze({ a: 1, b: "string" });
o.b = o.a.toString();
+4
View File
@@ -0,0 +1,4 @@
var intersection: { x: number, y: number } & { w: string, z: string };
var rest1: { y: number, w: string, z: string };
var {x, ...rest1 } = intersection;
@@ -0,0 +1,59 @@
enum E { v1, v2 };
function f<T extends { b: string }>(p1: T, p2: T[]) {
var t: T;
var i: T["b"];
var k: keyof T;
var mapped_generic: {[P in keyof T]: T[P]};
var mapped: {[P in "b"]: T[P]};
var union_generic: T | { a: number };
var union_primitive: { a: number } | number;
var intersection_generic: T & { a: number };
var intersection_premitive: { a: number } | string;
var num: number;
var str: number;
var u: undefined;
var n: null;
var a: any;
var literal_string: "string";
var literal_number: 42;
var e: E;
var {...r1} = p1; // Error, generic type paramterre
var {...r2} = p2; // OK
var {...r3} = t; // Error, generic type paramter
var {...r4} = i; // Error, index access
var {...r5} = k; // Error, index
var {...r6} = mapped_generic; // Error, generic mapped object type
var {...r7} = mapped; // OK, non-generic mapped type
var {...r8} = union_generic; // Error, union with generic type parameter
var {...r9} = union_primitive; // Error, union with generic type parameter
var {...r10} = intersection_generic; // Error, intersection with generic type parameter
var {...r11} = intersection_premitive; // Error, intersection with generic type parameter
var {...r12} = num; // Error
var {...r13} = str; // Error
var {...r14} = u; // OK
var {...r15} = n; // OK
var {...r16} = a; // OK
var {...r17} = literal_string; // Error
var {...r18} = literal_number; // Error
var {...r19} = e; // Error, enum
}
+14
View File
@@ -0,0 +1,14 @@
var union: { a: number, c: boolean } | { a: string, b: string };
var rest1: { c: boolean } | { b: string };
var {a, ...rest1 } = union;
var undefinedUnion: { n: number } | undefined;
var rest2: {};
var {n, ...rest2 } = undefinedUnion;
var nullUnion: { n: number } | null;
var rest3: {};
var {n, ...rest3 } = nullUnion;
+19
View File
@@ -0,0 +1,19 @@
// @strictNullChecks: true
declare const undefinedUnion: { n: number } | undefined;
var rest2: { n: number };
var {...rest2 } = undefinedUnion;
declare const nullUnion: { n: number } | null;
var rest3: { n: number };
var {...rest3 } = nullUnion;
declare const nullAndUndefinedUnion: null | undefined;
var rest4: { };
var {...rest4 } = nullAndUndefinedUnion;
declare const unionWithIntersection: ({ n: number } & { s: string }) & undefined | null;
var rest5: { n: number, s: string };
var {...rest5 } = unionWithIntersection;
@@ -0,0 +1,5 @@
// @noImplicitAny: true
let additional = [];
for (const subcomponent of [1, 2, 3]) {
additional = [...additional, subcomponent];
}
@@ -0,0 +1,7 @@
var intersection: { a: number } & { b: string };
var o1: { a: number, b: string };
var o1 = { ...intersection };
var o2: { a: number, b: string, c: boolean };
var o2 = { ...intersection, c: false };
@@ -0,0 +1,59 @@
enum E { v1, v2 };
function f<T extends { b: string }>(p1: T, p2: T[]) {
var t: T;
var i: T["b"];
var k: keyof T;
var mapped_generic: {[P in keyof T]: T[P]};
var mapped: {[P in "b"]: T[P]};
var union_generic: T | { a: number };
var union_primitive: { a: number } | number;
var intersection_generic: T & { a: number };
var intersection_premitive: { a: number } | string;
var num: number;
var str: number;
var u: undefined;
var n: null;
var a: any;
var literal_string: "string";
var literal_number: 42;
var e: E;
var o1 = { ...p1 }; // Error, generic type paramterre
var o2 = { ...p2 }; // OK
var o3 = { ...t }; // Error, generic type paramter
var o4 = { ...i }; // Error, index access
var o5 = { ...k }; // Error, index
var o6 = { ...mapped_generic }; // Error, generic mapped object type
var o7 = { ...mapped }; // OK, non-generic mapped type
var o8 = { ...union_generic }; // Error, union with generic type parameter
var o9 = { ...union_primitive }; // Error, union with generic type parameter
var o10 = { ...intersection_generic }; // Error, intersection with generic type parameter
var o11 = { ...intersection_premitive }; // Error, intersection with generic type parameter
var o12 = { ...num }; // Error
var o13 = { ...str }; // Error
var o14 = { ...u }; // OK
var o15 = { ...n }; // OK
var o16 = { ...a }; // OK
var o17 = { ...literal_string }; // Error
var o18 = { ...literal_number }; // Error
var o19 = { ...e }; // Error, enum
}
+10
View File
@@ -0,0 +1,10 @@
var union: { a: number } | { b: string };
var o3: { a: number } | { b: string };
var o3 = { ...union };
var o4: { a: boolean } | { b: string , a: boolean};
var o4 = { ...union, a: false };
var o5: { a: number } | { b: string } | { a: number, b: string };
var o5 = { ...union, ...union };
+25
View File
@@ -0,0 +1,25 @@
// @strictNullChecks: true
declare const undefinedUnion: { a: number } | undefined;
declare const nullUnion: { b: number } | null;
declare const nullAndUndefinedUnion: null | undefined;
var o1: { a: number };
var o1 = { ...undefinedUnion };
var o2: { b: number };
var o2 = { ...nullUnion };
var o3: { a: number, b: number };
var o3 = { ...undefinedUnion, ...nullUnion };
var o3 = { ...nullUnion, ...undefinedUnion };
var o4: { a: number };
var o4 = { ...undefinedUnion, ...undefinedUnion };
var o5: { b: number };
var o5 = { ...nullUnion, ...nullUnion };
var o6: { };
var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion };
var o6 = { ...nullAndUndefinedUnion };
@@ -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];
+4
View File
@@ -0,0 +1,4 @@
// @strictNullChecks: true
let a: number;
let b: typeof a;
@@ -0,0 +1,6 @@
type A = | string;
type B =
| { type: "INCREMENT" }
| { type: "DECREMENT" };
type C = [| 0 | 1, | "foo" | "bar"];
@@ -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;