mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-13 02:45:24 -05:00
Merge remote-tracking branch 'upstream/master' into javaScriptPrototypes
This commit is contained in:
20
tests/cases/compiler/genericSignatureIdentity.ts
Normal file
20
tests/cases/compiler/genericSignatureIdentity.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// This test is here to remind us of our current limits of type identity checking.
|
||||
// Ideally all of the below declarations would be considered different (and thus errors)
|
||||
// but they aren't because we erase type parameters to type any and don't check that
|
||||
// constraints are identical.
|
||||
|
||||
var x: {
|
||||
<T extends Date>(x: T): T;
|
||||
};
|
||||
|
||||
var x: {
|
||||
<T extends number>(x: T): T;
|
||||
};
|
||||
|
||||
var x: {
|
||||
<T>(x: T): T;
|
||||
};
|
||||
|
||||
var x: {
|
||||
<T>(x: any): any;
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @filename: a.js
|
||||
var a = 10;
|
||||
class a {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @filename: a.js
|
||||
// @target: es6
|
||||
export default class a {
|
||||
}
|
||||
export default var a = 10;
|
||||
@@ -0,0 +1,23 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @filename: a.js
|
||||
// @noFallthroughCasesInSwitch: true
|
||||
function foo(a, b) {
|
||||
switch (a) {
|
||||
case 10:
|
||||
if (b) {
|
||||
return b;
|
||||
}
|
||||
case 20:
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
function bar() {
|
||||
return x;
|
||||
function bar2() {
|
||||
}
|
||||
var x = 10; // error
|
||||
}
|
||||
|
||||
label1: var x2 = 10;
|
||||
@@ -0,0 +1,40 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @filename: a.js
|
||||
// @target: es6
|
||||
"use strict";
|
||||
var a = {
|
||||
a: "hello", // error
|
||||
b: 10,
|
||||
a: 10 // error
|
||||
};
|
||||
var let = 10; // error
|
||||
delete a; // error
|
||||
try {
|
||||
} catch (eval) { // error
|
||||
}
|
||||
function arguments() { // error
|
||||
}
|
||||
|
||||
with (a) {
|
||||
b = 10;
|
||||
}
|
||||
|
||||
// @filename: b.js
|
||||
// this is not in strict mode but class definitions are always in strict mode
|
||||
class c {
|
||||
a(eval) { //error
|
||||
}
|
||||
method() {
|
||||
var let = 10; // error
|
||||
}
|
||||
}
|
||||
|
||||
// @filename: c.js
|
||||
export var let = 10; // external modules are automatically in strict mode
|
||||
var eval = function () {
|
||||
};
|
||||
|
||||
//@filename: d.js
|
||||
"use strict";
|
||||
var x = 009; // error
|
||||
@@ -0,0 +1,16 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: moduleA/a.js
|
||||
import {a} from "b";
|
||||
a++;
|
||||
import {c} from "c";
|
||||
c++;
|
||||
|
||||
// @filename: node_modules/b.ts
|
||||
var a = 10;
|
||||
|
||||
// @filename: node_modules/c.js
|
||||
exports.a = 10;
|
||||
c = 10;
|
||||
9
tests/cases/compiler/unionTypeParameterInference.ts
Normal file
9
tests/cases/compiler/unionTypeParameterInference.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
// Regression test for #5861
|
||||
|
||||
interface Foo<T> { prop: T; }
|
||||
|
||||
declare function lift<U>(value: U | Foo<U>): Foo<U>;
|
||||
|
||||
function unlift<U>(value: U | Foo<U>): U {
|
||||
return lift(value).prop;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// @target: ES6
|
||||
// @noEmitHelpers: true
|
||||
type PromiseAlias<T> = Promise<T>;
|
||||
|
||||
async function f(): PromiseAlias<void> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// @target: es6
|
||||
// @module: commonjs
|
||||
// @filename: task.ts
|
||||
export class Task<T> extends Promise<T> { }
|
||||
|
||||
// @filename: test.ts
|
||||
import { Task } from "./task";
|
||||
class Test {
|
||||
async example<T>(): Task<T> { return; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @target: ES6
|
||||
// @noEmitHelpers: true
|
||||
namespace X {
|
||||
export class MyPromise<T> extends Promise<T> {
|
||||
}
|
||||
}
|
||||
|
||||
async function f(): X.MyPromise<void> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: amd
|
||||
// @filename: a.ts
|
||||
export default class {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function() {}
|
||||
@@ -1,8 +1,14 @@
|
||||
// @target: ES6
|
||||
// @experimentalDecorators: true
|
||||
// @module: amd
|
||||
|
||||
// @filename: a.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class {}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: amd
|
||||
// @filename: a.ts
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function foo() {}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// @target: ES6
|
||||
// @module: amd
|
||||
// @rootDir: tests/cases/conformance/es6/moduleExportsAmd/src
|
||||
// @outFile: output.js
|
||||
// @filename: src/a.ts
|
||||
import foo from "./b";
|
||||
export default class Foo {}
|
||||
foo();
|
||||
|
||||
// @filename: src/b.ts
|
||||
import Foo from "./a";
|
||||
export default function foo() { new Foo(); }
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: commonjs
|
||||
// @filename: a.ts
|
||||
export default class {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function() {}
|
||||
@@ -1,8 +1,14 @@
|
||||
// @target: ES6
|
||||
// @experimentalDecorators: true
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: a.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class {}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: commonjs
|
||||
// @filename: a.ts
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function foo() {}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: system
|
||||
// @filename: a.ts
|
||||
export default class {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function() {}
|
||||
@@ -1,8 +1,14 @@
|
||||
// @target: ES6
|
||||
// @experimentalDecorators: true
|
||||
// @module: system
|
||||
|
||||
// @filename: a.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class {}
|
||||
@@ -1,3 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: system
|
||||
// @filename: a.ts
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function foo() {}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// @target: ES6
|
||||
// @module: system
|
||||
// @rootDir: tests/cases/conformance/es6/moduleExportsSystem/src
|
||||
// @outFile: output.js
|
||||
// @filename: src/a.ts
|
||||
import foo from "./b";
|
||||
export default class Foo {}
|
||||
foo();
|
||||
|
||||
// @filename: src/b.ts
|
||||
import Foo from "./a";
|
||||
export default function foo() { new Foo(); }
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: umd
|
||||
// @filename: a.ts
|
||||
export default class {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function() {}
|
||||
@@ -1,8 +1,14 @@
|
||||
// @target: ES6
|
||||
// @experimentalDecorators: true
|
||||
// @module: umd
|
||||
|
||||
// @filename: a.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
var decorator: ClassDecorator;
|
||||
|
||||
@decorator
|
||||
export default class {}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// @target: ES6
|
||||
// @module: umd
|
||||
// @filename: a.ts
|
||||
export default class Foo {}
|
||||
|
||||
// @filename: b.ts
|
||||
export default function foo() {}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// @filename: file.tsx
|
||||
// @jsx: preserve
|
||||
// @noLib: true
|
||||
// @libFiles: react.d.ts,lib.d.ts
|
||||
|
||||
function Greet(x: {name: string}) {
|
||||
return <div>Hello, {x}</div>;
|
||||
}
|
||||
function Meet({name = 'world'}) {
|
||||
return <div>Hello, {name}</div>;
|
||||
}
|
||||
|
||||
// OK
|
||||
let a = <Greet name='world' />;
|
||||
// Error
|
||||
let b = <Greet naaame='world' />;
|
||||
|
||||
// OK
|
||||
let c = <Meet />;
|
||||
// OK
|
||||
let d = <Meet name='me' />;
|
||||
// Error
|
||||
let e = <Meet name={42} />;
|
||||
// Error
|
||||
let f = <Meet naaaaaaame='no' />;
|
||||
@@ -0,0 +1,41 @@
|
||||
// @filename: file.tsx
|
||||
// @jsx: preserve
|
||||
// @noLib: true
|
||||
// @libFiles: react.d.ts,lib.d.ts
|
||||
|
||||
import React = require('react');
|
||||
|
||||
function Greet(x: {name?: string}) {
|
||||
return <div>Hello, {x}</div>;
|
||||
}
|
||||
|
||||
class BigGreeter extends React.Component<{ name?: string }, {}> {
|
||||
render() {
|
||||
return <div></div>;
|
||||
}
|
||||
greeting: string;
|
||||
}
|
||||
|
||||
// OK
|
||||
let a = <Greet />;
|
||||
// OK - always valid to specify 'key'
|
||||
let b = <Greet key="k" />;
|
||||
// Error - not allowed to specify 'ref' on SFCs
|
||||
let c = <Greet ref="myRef" />;
|
||||
|
||||
|
||||
// OK - ref is valid for classes
|
||||
let d = <BigGreeter ref={x => x.greeting.substr(10)} />;
|
||||
// Error ('subtr' not on string)
|
||||
let e = <BigGreeter ref={x => x.greeting.subtr(10)} />;
|
||||
// Error (ref callback is contextually typed)
|
||||
let f = <BigGreeter ref={x => x.notARealProperty} />;
|
||||
|
||||
// OK - key is always valid
|
||||
let g = <BigGreeter key={100} />;
|
||||
|
||||
// OK - contextually typed intrinsic ref callback parameter
|
||||
let h = <div ref={x => x.innerText} />;
|
||||
// Error - property not on ontextually typed intrinsic ref callback parameter
|
||||
let i = <div ref={x => x.propertyNotOnHtmlDivElement} />;
|
||||
|
||||
@@ -11,5 +11,12 @@ verify.getSemanticDiagnostics(`[
|
||||
"length": 11,
|
||||
"category": "error",
|
||||
"code": 8003
|
||||
},
|
||||
{
|
||||
"message": "Cannot compile modules unless the '--module' flag is provided.",
|
||||
"start": 0,
|
||||
"length": 11,
|
||||
"category": "error",
|
||||
"code": 1148
|
||||
}
|
||||
]`);
|
||||
@@ -0,0 +1,19 @@
|
||||
///<reference path="fourslash.ts" />
|
||||
|
||||
//// type Ctor<AA> = new () => A/*1*/A;
|
||||
//// type MixinCtor<AA> = new () => AA & { constructor: MixinCtor<A/*2*/A> };
|
||||
//// type NestedCtor<AA> = new() => AA & (new () => AA & { constructor: NestedCtor<A/*3*/A> });
|
||||
//// type Method<AA> = { method(): A/*4*/A };
|
||||
//// type Construct<AA> = { new(): A/*5*/A };
|
||||
|
||||
|
||||
goTo.marker('1');
|
||||
verify.quickInfoIs('(type parameter) AA in type Ctor<AA>');
|
||||
goTo.marker('2');
|
||||
verify.quickInfoIs('(type parameter) AA in type MixinCtor<AA>');
|
||||
goTo.marker('3');
|
||||
verify.quickInfoIs('(type parameter) AA in type NestedCtor<AA>');
|
||||
goTo.marker('4');
|
||||
verify.quickInfoIs('(type parameter) AA in type Method<AA>');
|
||||
goTo.marker('5');
|
||||
verify.quickInfoIs('(type parameter) AA in type Construct<AA>');
|
||||
@@ -0,0 +1,22 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// type Call<AA> = { (): A/*1*/A };
|
||||
//// type Index<AA> = {[foo: string]: A/*2*/A};
|
||||
//// type GenericMethod<AA> = { method<BB>(): A/*3*/A & B/*4*/B }
|
||||
//// type Nesting<TT> = { method<UU>(): new <WW>() => T/*5*/T & U/*6*/U & W/*7*/W };
|
||||
|
||||
goTo.marker('1');
|
||||
verify.quickInfoIs('(type parameter) AA in type Call<AA>');
|
||||
goTo.marker('2');
|
||||
verify.quickInfoIs('(type parameter) AA in type Index<AA>');
|
||||
goTo.marker('3');
|
||||
verify.quickInfoIs('(type parameter) AA in type GenericMethod<AA>');
|
||||
goTo.marker('4');
|
||||
verify.quickInfoIs('(type parameter) BB in method<BB>(): AA & BB');
|
||||
goTo.marker('5');
|
||||
verify.quickInfoIs('(type parameter) TT in type Nesting<TT>');
|
||||
goTo.marker('6');
|
||||
verify.quickInfoIs('(type parameter) UU in method<UU>(): new <WW>() => TT & UU & WW');
|
||||
goTo.marker('7');
|
||||
verify.quickInfoIs('(type parameter) WW in <WW>(): TT & UU & WW');
|
||||
|
||||
Reference in New Issue
Block a user