mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
merge with master
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// @target: ES5
|
||||
// @sourcemap: true
|
||||
// @declaration: true
|
||||
// @module: amd
|
||||
// @outFile: all.js
|
||||
|
||||
// @Filename: ref/a.ts
|
||||
export class A { }
|
||||
|
||||
// @Filename: b.ts
|
||||
import {A} from "./ref/a";
|
||||
export class B extends A { }
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target: ES5
|
||||
// @sourcemap: true
|
||||
// @declaration: true
|
||||
// @module: commonjs
|
||||
// @outFile: all.js
|
||||
|
||||
// This should be an error
|
||||
|
||||
// @Filename: ref/a.ts
|
||||
export class A { }
|
||||
|
||||
// @Filename: b.ts
|
||||
import {A} from "./ref/a";
|
||||
export class B extends A { }
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target: ES6
|
||||
// @sourcemap: true
|
||||
// @declaration: true
|
||||
// @module: es6
|
||||
// @outFile: all.js
|
||||
|
||||
// This should be an error
|
||||
|
||||
// @Filename: ref/a.ts
|
||||
export class A { }
|
||||
|
||||
// @Filename: b.ts
|
||||
import {A} from "./ref/a";
|
||||
export class B extends A { }
|
||||
@@ -0,0 +1,12 @@
|
||||
// @target: ES5
|
||||
// @sourcemap: true
|
||||
// @declaration: true
|
||||
// @module: system
|
||||
// @outFile: all.js
|
||||
|
||||
// @Filename: ref/a.ts
|
||||
export class A { }
|
||||
|
||||
// @Filename: b.ts
|
||||
import {A} from "./ref/a";
|
||||
export class B extends A { }
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target: ES5
|
||||
// @sourcemap: true
|
||||
// @declaration: true
|
||||
// @module: umd
|
||||
// @outFile: all.js
|
||||
|
||||
// This should error
|
||||
|
||||
// @Filename: ref/a.ts
|
||||
export class A { }
|
||||
|
||||
// @Filename: b.ts
|
||||
import {A} from "./ref/a";
|
||||
export class B extends A { }
|
||||
@@ -0,0 +1,33 @@
|
||||
// @target: ES5
|
||||
// @sourcemap: true
|
||||
// @declaration: true
|
||||
// @module: amd
|
||||
// @outFile: all.js
|
||||
|
||||
// @Filename: ref/a.ts
|
||||
/// <reference path="./b.ts" />
|
||||
export class A {
|
||||
member: typeof GlobalFoo;
|
||||
}
|
||||
|
||||
// @Filename: ref/b.ts
|
||||
/// <reference path="./c.d.ts" />
|
||||
class Foo {
|
||||
member: Bar;
|
||||
}
|
||||
declare var GlobalFoo: Foo;
|
||||
|
||||
// @Filename: ref/c.d.ts
|
||||
/// <reference path="./d.d.ts" />
|
||||
declare class Bar {
|
||||
member: Baz;
|
||||
}
|
||||
|
||||
// @Filename: ref/d.d.ts
|
||||
declare class Baz {
|
||||
member: number;
|
||||
}
|
||||
|
||||
// @Filename: b.ts
|
||||
import {A} from "./ref/a";
|
||||
export class B extends A { }
|
||||
@@ -0,0 +1,16 @@
|
||||
// @target: ES6
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: existingModule.ts
|
||||
export var x = 1;
|
||||
|
||||
// @filename: test.ts
|
||||
import {x} from './existingModule';
|
||||
import {foo} from './missingModule';
|
||||
|
||||
declare function use(a: any): void;
|
||||
|
||||
const test = { x, foo };
|
||||
|
||||
use(x);
|
||||
use(foo);
|
||||
@@ -1,4 +1,3 @@
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
var f: <T extends UNKNOWN>() => void;
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target: es6
|
||||
class C {
|
||||
get x(): <T>(a: T) => T { return null; }
|
||||
set x(p: <U>(a: U) => U) {}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
type S = "a" | "b";
|
||||
type T = S[] | S;
|
||||
|
||||
function f(foo: T) {
|
||||
if (foo === "a") {
|
||||
return foo;
|
||||
}
|
||||
else if (foo === "b") {
|
||||
return foo;
|
||||
}
|
||||
else {
|
||||
return (foo as S[])[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
type S = "a" | "b";
|
||||
type T = S[] | S;
|
||||
|
||||
function isS(t: T): t is S {
|
||||
return t === "a" || t === "b";
|
||||
}
|
||||
|
||||
function f(foo: T) {
|
||||
if (isS(foo)) {
|
||||
return foo;
|
||||
}
|
||||
else {
|
||||
return foo[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
type S = "a" | "b";
|
||||
type T = S[] | S;
|
||||
|
||||
var foo: T;
|
||||
switch (foo) {
|
||||
case "a":
|
||||
case "b":
|
||||
break;
|
||||
default:
|
||||
foo = (foo as S[])[0];
|
||||
break;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
type S = "a" | "b";
|
||||
type T = S[] | S;
|
||||
|
||||
var s: S;
|
||||
var t: T;
|
||||
var str: string;
|
||||
|
||||
////////////////
|
||||
|
||||
s = <S>t;
|
||||
s = t as S;
|
||||
|
||||
s = <S>str;
|
||||
s = str as S;
|
||||
|
||||
////////////////
|
||||
|
||||
t = <T>s;
|
||||
t = s as T;
|
||||
|
||||
t = <T>str;
|
||||
t = str as T;
|
||||
|
||||
////////////////
|
||||
|
||||
str = <string>s;
|
||||
str = s as string;
|
||||
|
||||
str = <string>t;
|
||||
str = t as string;
|
||||
@@ -0,0 +1,20 @@
|
||||
// @declaration: true
|
||||
|
||||
// Should all be strings.
|
||||
let [hello, brave, newish, world] = ["Hello", "Brave", "New", "World"];
|
||||
|
||||
type RexOrRaptor = "t-rex" | "raptor"
|
||||
let [im, a, dinosaur]: ["I'm", "a", RexOrRaptor] = ['I\'m', 'a', 't-rex'];
|
||||
|
||||
rawr(dinosaur);
|
||||
|
||||
function rawr(dino: RexOrRaptor) {
|
||||
if (dino === "t-rex") {
|
||||
return "ROAAAAR!";
|
||||
}
|
||||
if (dino === "raptor") {
|
||||
return "yip yip!";
|
||||
}
|
||||
|
||||
throw "Unexpected " + dino;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// @declaration: true
|
||||
|
||||
type Kind = "A" | "B"
|
||||
|
||||
interface Entity {
|
||||
kind: Kind;
|
||||
}
|
||||
|
||||
interface A extends Entity {
|
||||
kind: "A";
|
||||
a: number;
|
||||
}
|
||||
|
||||
interface B extends Entity {
|
||||
kind: "B";
|
||||
b: string;
|
||||
}
|
||||
|
||||
function hasKind(entity: Entity, kind: "A"): entity is A;
|
||||
function hasKind(entity: Entity, kind: "B"): entity is B;
|
||||
function hasKind(entity: Entity, kind: Kind): entity is Entity;
|
||||
function hasKind(entity: Entity, kind: Kind): boolean {
|
||||
return kind === is;
|
||||
}
|
||||
|
||||
let x: A = {
|
||||
kind: "A",
|
||||
a: 100,
|
||||
}
|
||||
|
||||
if (hasKind(x, "A")) {
|
||||
let a = x;
|
||||
}
|
||||
else {
|
||||
let b = x;
|
||||
}
|
||||
|
||||
if (!hasKind(x, "B")) {
|
||||
let c = x;
|
||||
}
|
||||
else {
|
||||
let d = x;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// @declaration: true
|
||||
|
||||
type T = "foo" | "bar" | "baz";
|
||||
|
||||
var x: "foo" | "bar" | "baz" = "foo";
|
||||
var y: T = "bar";
|
||||
|
||||
if (x === "foo") {
|
||||
let a = x;
|
||||
}
|
||||
else if (x !== "bar") {
|
||||
let b = x || y;
|
||||
}
|
||||
else {
|
||||
let c = x;
|
||||
let d = y;
|
||||
let e: (typeof x) | (typeof y) = c || d;
|
||||
}
|
||||
|
||||
x = y;
|
||||
y = x;
|
||||
@@ -0,0 +1,21 @@
|
||||
// @declaration: true
|
||||
|
||||
type T = string | "foo" | "bar" | "baz";
|
||||
|
||||
var x: "foo" | "bar" | "baz" | string = "foo";
|
||||
var y: T = "bar";
|
||||
|
||||
if (x === "foo") {
|
||||
let a = x;
|
||||
}
|
||||
else if (x !== "bar") {
|
||||
let b = x || y;
|
||||
}
|
||||
else {
|
||||
let c = x;
|
||||
let d = y;
|
||||
let e: (typeof x) | (typeof y) = c || d;
|
||||
}
|
||||
|
||||
x = y;
|
||||
y = x;
|
||||
@@ -0,0 +1,21 @@
|
||||
// @declaration: true
|
||||
|
||||
type T = number | "foo" | "bar";
|
||||
|
||||
var x: "foo" | "bar" | number;
|
||||
var y: T = "bar";
|
||||
|
||||
if (x === "foo") {
|
||||
let a = x;
|
||||
}
|
||||
else if (x !== "bar") {
|
||||
let b = x || y;
|
||||
}
|
||||
else {
|
||||
let c = x;
|
||||
let d = y;
|
||||
let e: (typeof x) | (typeof y) = c || d;
|
||||
}
|
||||
|
||||
x = y;
|
||||
y = x;
|
||||
@@ -0,0 +1,38 @@
|
||||
// @declaration: true
|
||||
|
||||
type T = "" | "foo";
|
||||
|
||||
let x: T = "";
|
||||
let y: T = "foo";
|
||||
|
||||
if (x === "") {
|
||||
let a = x;
|
||||
}
|
||||
|
||||
if (x !== "") {
|
||||
let b = x;
|
||||
}
|
||||
|
||||
if (x == "") {
|
||||
let c = x;
|
||||
}
|
||||
|
||||
if (x != "") {
|
||||
let d = x;
|
||||
}
|
||||
|
||||
if (x) {
|
||||
let e = x;
|
||||
}
|
||||
|
||||
if (!x) {
|
||||
let f = x;
|
||||
}
|
||||
|
||||
if (!!x) {
|
||||
let g = x;
|
||||
}
|
||||
|
||||
if (!!!x) {
|
||||
let h = x;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// @declaration: true
|
||||
|
||||
let a: "";
|
||||
var b: "foo";
|
||||
let c: "bar";
|
||||
const d: "baz";
|
||||
|
||||
a = "";
|
||||
b = "foo";
|
||||
c = "bar";
|
||||
|
||||
let e: "" = "";
|
||||
var f: "foo" = "foo";
|
||||
let g: "bar" = "bar";
|
||||
const h: "baz" = "baz";
|
||||
|
||||
e = "";
|
||||
f = "foo";
|
||||
g = "bar";
|
||||
@@ -0,0 +1,53 @@
|
||||
// @declaration: true
|
||||
|
||||
type PrimitiveName = 'string' | 'number' | 'boolean';
|
||||
|
||||
function getFalsyPrimitive(x: "string"): string;
|
||||
function getFalsyPrimitive(x: "number"): number;
|
||||
function getFalsyPrimitive(x: "boolean"): boolean;
|
||||
function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
|
||||
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
|
||||
function getFalsyPrimitive(x: "number" | "string"): number | string;
|
||||
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
|
||||
function getFalsyPrimitive(x: PrimitiveName) {
|
||||
if (x === "string") {
|
||||
return "";
|
||||
}
|
||||
if (x === "number") {
|
||||
return 0;
|
||||
}
|
||||
if (x === "boolean") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Should be unreachable.
|
||||
throw "Invalid value";
|
||||
}
|
||||
|
||||
namespace Consts1 {
|
||||
const EMPTY_STRING = getFalsyPrimitive("string");
|
||||
const ZERO = getFalsyPrimitive('number');
|
||||
const FALSE = getFalsyPrimitive("boolean");
|
||||
}
|
||||
|
||||
const string: "string" = "string"
|
||||
const number: "number" = "number"
|
||||
const boolean: "boolean" = "boolean"
|
||||
|
||||
const stringOrNumber = string || number;
|
||||
const stringOrBoolean = string || boolean;
|
||||
const booleanOrNumber = number || boolean;
|
||||
const stringOrBooleanOrNumber = stringOrBoolean || number;
|
||||
|
||||
namespace Consts2 {
|
||||
const EMPTY_STRING = getFalsyPrimitive(string);
|
||||
const ZERO = getFalsyPrimitive(number);
|
||||
const FALSE = getFalsyPrimitive(boolean);
|
||||
|
||||
const a = getFalsyPrimitive(stringOrNumber);
|
||||
const b = getFalsyPrimitive(stringOrBoolean);
|
||||
const c = getFalsyPrimitive(booleanOrNumber);
|
||||
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// @declaration: true
|
||||
|
||||
function getFalsyPrimitive(x: "string"): string;
|
||||
function getFalsyPrimitive(x: "number"): number;
|
||||
function getFalsyPrimitive(x: "boolean"): boolean;
|
||||
function getFalsyPrimitive(x: "boolean" | "string"): boolean | string;
|
||||
function getFalsyPrimitive(x: "boolean" | "number"): boolean | number;
|
||||
function getFalsyPrimitive(x: "number" | "string"): number | string;
|
||||
function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean;
|
||||
function getFalsyPrimitive(x: string) {
|
||||
if (x === "string") {
|
||||
return "";
|
||||
}
|
||||
if (x === "number") {
|
||||
return 0;
|
||||
}
|
||||
if (x === "boolean") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Should be unreachable.
|
||||
throw "Invalid value";
|
||||
}
|
||||
|
||||
namespace Consts1 {
|
||||
const EMPTY_STRING = getFalsyPrimitive("string");
|
||||
const ZERO = getFalsyPrimitive('number');
|
||||
const FALSE = getFalsyPrimitive("boolean");
|
||||
}
|
||||
|
||||
const string: "string" = "string"
|
||||
const number: "number" = "number"
|
||||
const boolean: "boolean" = "boolean"
|
||||
|
||||
const stringOrNumber = string || number;
|
||||
const stringOrBoolean = string || boolean;
|
||||
const booleanOrNumber = number || boolean;
|
||||
const stringOrBooleanOrNumber = stringOrBoolean || number;
|
||||
|
||||
namespace Consts2 {
|
||||
const EMPTY_STRING = getFalsyPrimitive(string);
|
||||
const ZERO = getFalsyPrimitive(number);
|
||||
const FALSE = getFalsyPrimitive(boolean);
|
||||
|
||||
const a = getFalsyPrimitive(stringOrNumber);
|
||||
const b = getFalsyPrimitive(stringOrBoolean);
|
||||
const c = getFalsyPrimitive(booleanOrNumber);
|
||||
const d = getFalsyPrimitive(stringOrBooleanOrNumber);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// @declaration: true
|
||||
|
||||
interface Base {
|
||||
x: string;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface HelloOrWorld extends Base {
|
||||
p1: boolean;
|
||||
}
|
||||
|
||||
interface JustHello extends Base {
|
||||
p2: boolean;
|
||||
}
|
||||
|
||||
interface JustWorld extends Base {
|
||||
p3: boolean;
|
||||
}
|
||||
|
||||
let hello: "hello";
|
||||
let world: "world";
|
||||
let helloOrWorld: "hello" | "world";
|
||||
|
||||
function f(p: "hello"): JustHello;
|
||||
function f(p: "hello" | "world"): HelloOrWorld;
|
||||
function f(p: "world"): JustWorld;
|
||||
function f(p: string): Base;
|
||||
function f(...args: any[]): any {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let fResult1 = f(hello);
|
||||
let fResult2 = f(world);
|
||||
let fResult3 = f(helloOrWorld);
|
||||
|
||||
function g(p: string): Base;
|
||||
function g(p: "hello"): JustHello;
|
||||
function g(p: "hello" | "world"): HelloOrWorld;
|
||||
function g(p: "world"): JustWorld;
|
||||
function g(...args: any[]): any {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let gResult1 = g(hello);
|
||||
let gResult2 = g(world);
|
||||
let gResult3 = g(helloOrWorld);
|
||||
@@ -0,0 +1,25 @@
|
||||
// @declaration: true
|
||||
|
||||
type Kind = "A" | "B"
|
||||
|
||||
function kindIs(kind: Kind, is: "A"): kind is "A";
|
||||
function kindIs(kind: Kind, is: "B"): kind is "B";
|
||||
function kindIs(kind: Kind, is: Kind): boolean {
|
||||
return kind === is;
|
||||
}
|
||||
|
||||
var x: Kind = "A";
|
||||
|
||||
if (kindIs(x, "A")) {
|
||||
let a = x;
|
||||
}
|
||||
else {
|
||||
let b = x;
|
||||
}
|
||||
|
||||
if (!kindIs(x, "B")) {
|
||||
let c = x;
|
||||
}
|
||||
else {
|
||||
let d = x;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// @declaration: true
|
||||
|
||||
let ABC: "ABC" = `ABC`;
|
||||
let DE_NEWLINE_F: "DE\nF" = `DE
|
||||
F`;
|
||||
let G_QUOTE_HI: 'G"HI';
|
||||
let JK_BACKTICK_L: "JK`L" = `JK\`L`;
|
||||
@@ -0,0 +1,5 @@
|
||||
// @declaration: true
|
||||
|
||||
let abc: "AB\r\nC" = `AB
|
||||
C`;
|
||||
let de_NEWLINE_f: "DE\nF" = `DE${"\n"}F`;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// @declaration: true
|
||||
|
||||
let abc: "ABC" = "ABC";
|
||||
let xyz: "XYZ" = "XYZ";
|
||||
let abcOrXyz: "ABC" | "XYZ" = abc || xyz;
|
||||
let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100;
|
||||
|
||||
let a = "" + abc;
|
||||
let b = abc + "";
|
||||
let c = 10 + abc;
|
||||
let d = abc + 10;
|
||||
let e = xyz + abc;
|
||||
let f = abc + xyz;
|
||||
let g = true + abc;
|
||||
let h = abc + true;
|
||||
let i = abc + abcOrXyz + xyz;
|
||||
let j = abcOrXyz + abcOrXyz;
|
||||
let k = +abcOrXyz;
|
||||
let l = -abcOrXyz;
|
||||
let m = abcOrXyzOrNumber + "";
|
||||
let n = "" + abcOrXyzOrNumber;
|
||||
let o = abcOrXyzOrNumber + abcOrXyz;
|
||||
let p = abcOrXyz + abcOrXyzOrNumber;
|
||||
let q = !abcOrXyzOrNumber;
|
||||
let r = ~abcOrXyzOrNumber;
|
||||
let s = abcOrXyzOrNumber < abcOrXyzOrNumber;
|
||||
let t = abcOrXyzOrNumber >= abcOrXyz;
|
||||
let u = abc === abcOrXyz;
|
||||
let v = abcOrXyz === abcOrXyzOrNumber;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// @declaration: true
|
||||
|
||||
let abc: "ABC" = "ABC";
|
||||
let xyz: "XYZ" = "XYZ";
|
||||
let abcOrXyz: "ABC" | "XYZ" = abc || xyz;
|
||||
let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100;
|
||||
|
||||
let a = abcOrXyzOrNumber + 100;
|
||||
let b = 100 + abcOrXyzOrNumber;
|
||||
let c = abcOrXyzOrNumber + abcOrXyzOrNumber;
|
||||
let d = abcOrXyzOrNumber + true;
|
||||
let e = false + abcOrXyzOrNumber;
|
||||
let f = abcOrXyzOrNumber++;
|
||||
let g = --abcOrXyzOrNumber;
|
||||
let h = abcOrXyzOrNumber ^ 10;
|
||||
let i = abcOrXyzOrNumber | 10;
|
||||
let j = abc < xyz;
|
||||
let k = abc === xyz;
|
||||
let l = abc != xyz;
|
||||
@@ -0,0 +1,113 @@
|
||||
// @declaration: true
|
||||
|
||||
declare function randBool(): boolean;
|
||||
declare function takeReturnString(str: string): string;
|
||||
declare function takeReturnHello(str: "Hello"): "Hello";
|
||||
declare function takeReturnHelloWorld(str: "Hello" | "World"): "Hello" | "World";
|
||||
|
||||
function fun1<T>(x: T, y: T) {
|
||||
return randBool() ? x : y;
|
||||
}
|
||||
|
||||
function fun2<T, U>(x: T, y: U) {
|
||||
return randBool() ? x : y;
|
||||
}
|
||||
|
||||
function fun3<T>(...args: T[]): T {
|
||||
return args[+randBool()];
|
||||
}
|
||||
|
||||
namespace n1 {
|
||||
// The following should all come back as strings.
|
||||
// They should be assignable to/from something of a type 'string'.
|
||||
// They should not be assignable to either "Hello" or "World".
|
||||
export let a = fun1("Hello", "World");
|
||||
export let b = fun1("Hello", "Hello");
|
||||
export let c = fun2("Hello", "World");
|
||||
export let d = fun2("Hello", "Hello");
|
||||
export let e = fun3("Hello", "Hello", "World", "Foo");
|
||||
|
||||
// Should be valid
|
||||
a = takeReturnString(a);
|
||||
b = takeReturnString(b);
|
||||
c = takeReturnString(c);
|
||||
d = takeReturnString(d);
|
||||
e = takeReturnString(e);
|
||||
|
||||
// Passing these as arguments should cause an error.
|
||||
a = takeReturnHello(a);
|
||||
b = takeReturnHello(b);
|
||||
c = takeReturnHello(c);
|
||||
d = takeReturnHello(d);
|
||||
e = takeReturnHello(e);
|
||||
|
||||
// Passing these as arguments should cause an error.
|
||||
a = takeReturnHelloWorld(a);
|
||||
b = takeReturnHelloWorld(b);
|
||||
c = takeReturnHelloWorld(c);
|
||||
d = takeReturnHelloWorld(d);
|
||||
e = takeReturnHelloWorld(e);
|
||||
}
|
||||
|
||||
namespace n2 {
|
||||
// The following (regardless of errors) should come back typed
|
||||
// as "Hello" (or "Hello" | "Hello").
|
||||
export let a = fun1<"Hello">("Hello", "Hello");
|
||||
export let b = fun1<"Hello">("Hello", "World");
|
||||
export let c = fun2<"Hello", "Hello">("Hello", "Hello");
|
||||
export let d = fun2<"Hello", "Hello">("Hello", "World");
|
||||
export let e = fun3<"Hello">("Hello", "World");
|
||||
|
||||
// Assignment from the returned value should cause an error.
|
||||
a = takeReturnString(a);
|
||||
b = takeReturnString(b);
|
||||
c = takeReturnString(c);
|
||||
d = takeReturnString(d);
|
||||
e = takeReturnString(e);
|
||||
|
||||
// Should be valid
|
||||
a = takeReturnHello(a);
|
||||
b = takeReturnHello(b);
|
||||
c = takeReturnHello(c);
|
||||
d = takeReturnHello(d);
|
||||
e = takeReturnHello(e);
|
||||
|
||||
// Assignment from the returned value should cause an error.
|
||||
a = takeReturnHelloWorld(a);
|
||||
b = takeReturnHelloWorld(b);
|
||||
c = takeReturnHelloWorld(c);
|
||||
d = takeReturnHelloWorld(d);
|
||||
e = takeReturnHelloWorld(e);
|
||||
}
|
||||
|
||||
|
||||
namespace n3 {
|
||||
// The following (regardless of errors) should come back typed
|
||||
// as "Hello" | "World" (or "World" | "Hello").
|
||||
export let a = fun2<"Hello", "World">("Hello", "World");
|
||||
export let b = fun2<"Hello", "World">("World", "Hello");
|
||||
export let c = fun2<"World", "Hello">("Hello", "Hello");
|
||||
export let d = fun2<"World", "Hello">("World", "World");
|
||||
export let e = fun3<"Hello" | "World">("Hello", "World");
|
||||
|
||||
// Assignment from the returned value should cause an error.
|
||||
a = takeReturnString(a);
|
||||
b = takeReturnString(b);
|
||||
c = takeReturnString(c);
|
||||
d = takeReturnString(d);
|
||||
e = takeReturnString(e);
|
||||
|
||||
// Passing these as arguments should cause an error.
|
||||
a = takeReturnHello(a);
|
||||
b = takeReturnHello(b);
|
||||
c = takeReturnHello(c);
|
||||
d = takeReturnHello(d);
|
||||
e = takeReturnHello(e);
|
||||
|
||||
// Both should be valid.
|
||||
a = takeReturnHelloWorld(a);
|
||||
b = takeReturnHelloWorld(b);
|
||||
c = takeReturnHelloWorld(c);
|
||||
d = takeReturnHelloWorld(d);
|
||||
e = takeReturnHelloWorld(e);
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
goTo.marker('1');
|
||||
verify.signatureHelpCountIs(4);
|
||||
verify.currentSignatureHelpIs('foo(name: \'order\'): string');
|
||||
verify.currentSignatureHelpIs('foo(name: "order"): string');
|
||||
edit.insert('"hi"');
|
||||
|
||||
goTo.marker('2');
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////let /*1*/hello: "hello" | 'hello' = "hello";
|
||||
////let /*2*/world: 'world' = "world";
|
||||
////let /*3*/helloOrWorld: "hello" | 'world';
|
||||
|
||||
goTo.marker("1");
|
||||
verify.verifyQuickInfoDisplayParts("let", "", { start: test.markerByName('1').position, length: "hello".length }, [
|
||||
{ text: "let", kind: "keyword" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: "hello", kind: "localName" },
|
||||
{ text: ":", kind: "punctuation" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: '"hello"', kind: "stringLiteral" }, ],
|
||||
/*documentation*/ []);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.verifyQuickInfoDisplayParts("let", "", { start: test.markerByName('2').position, length: "world".length }, [
|
||||
{ text: "let", kind: "keyword" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: "world", kind: "localName" },
|
||||
{ text: ":", kind: "punctuation" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: '"world"', kind: "stringLiteral" },
|
||||
],
|
||||
/*documentation*/[]);
|
||||
|
||||
goTo.marker("3");
|
||||
verify.verifyQuickInfoDisplayParts("let", "", { start: test.markerByName('3').position, length: "helloOrWorld".length }, [
|
||||
{ text: "let", kind: "keyword" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: "helloOrWorld", kind: "localName" },
|
||||
{ text: ":", kind: "punctuation" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: '"hello"', kind: "stringLiteral" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: "|", kind: "punctuation" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: '"world"', kind: "stringLiteral" },
|
||||
],
|
||||
/*documentation*/[]);
|
||||
@@ -20,22 +20,22 @@
|
||||
////c.x1(1, (x/*10*/x) => { return 1; } );
|
||||
|
||||
goTo.marker('1');
|
||||
verify.quickInfoIs("(method) I.x1(a: number, callback: (x: 'hi') => number): any");
|
||||
verify.quickInfoIs("(method) I.x1(a: number, callback: (x: \"hi\") => number): any");
|
||||
goTo.marker('2');
|
||||
verify.quickInfoIs("(method) C.x1(a: number, callback: (x: 'hi') => number): any");
|
||||
verify.quickInfoIs("(method) C.x1(a: number, callback: (x: \"hi\") => number): any");
|
||||
goTo.marker('3');
|
||||
verify.quickInfoIs("(parameter) callback: (x: 'hi') => number");
|
||||
verify.quickInfoIs("(parameter) callback: (x: \"hi\") => number");
|
||||
goTo.marker('4');
|
||||
verify.quickInfoIs("(method) C.x1(a: number, callback: (x: 'hi') => number): any");
|
||||
verify.quickInfoIs("(method) C.x1(a: number, callback: (x: \"hi\") => number): any");
|
||||
goTo.marker('5');
|
||||
verify.quickInfoIs('(parameter) callback: (x: string) => number');
|
||||
goTo.marker('6');
|
||||
verify.quickInfoIs('(parameter) callback: (x: string) => number');
|
||||
goTo.marker('7');
|
||||
verify.quickInfoIs("(method) C.x1(a: number, callback: (x: 'hi') => number): any");
|
||||
verify.quickInfoIs("(method) C.x1(a: number, callback: (x: \"hi\") => number): any");
|
||||
goTo.marker('8');
|
||||
verify.quickInfoIs("(parameter) xx: 'hi'");
|
||||
verify.quickInfoIs("(parameter) xx: \"hi\"");
|
||||
goTo.marker('9');
|
||||
verify.quickInfoIs("(parameter) xx: 'bye'");
|
||||
verify.quickInfoIs("(parameter) xx: \"bye\"");
|
||||
goTo.marker('10');
|
||||
verify.quickInfoIs("(parameter) xx: 'hi'");
|
||||
verify.quickInfoIs("(parameter) xx: \"hi\"");
|
||||
@@ -18,9 +18,9 @@ verify.currentParameterSpanIs("z: string");
|
||||
goTo.marker('2');
|
||||
verify.signatureHelpCountIs(3);
|
||||
verify.currentParameterHelpArgumentNameIs("x");
|
||||
verify.currentParameterSpanIs("x: 'hi'");
|
||||
verify.currentParameterSpanIs("x: \"hi\"");
|
||||
|
||||
goTo.marker('3');
|
||||
verify.signatureHelpCountIs(3);
|
||||
verify.currentParameterHelpArgumentNameIs("y");
|
||||
verify.currentParameterSpanIs("y: 'bye'");
|
||||
verify.currentParameterSpanIs("y: \"bye\"");
|
||||
|
||||
Reference in New Issue
Block a user