Add test cases and baselines.

This commit is contained in:
Nathan Shively-Sanders
2016-02-29 10:15:23 -08:00
parent c68947e0fb
commit 0d37241394
7 changed files with 349 additions and 0 deletions
@@ -0,0 +1,41 @@
//// [contextuallyTypedBindingInitializer.ts]
interface Show {
show: (x: number) => string;
}
function f({ show = v => v.toString() }: Show) {}
interface Nested {
nested: Show
}
function ff({ nested = { show: v => v.toString() } }: Nested) {}
interface Tuples {
prop: [string, number];
}
function g({ prop = ["hello", 1234] }: Tuples) {}
interface StringUnion {
prop: "foo" | "bar";
}
function h({ prop = "foo" }: StringUnion) {}
interface StringIdentity {
stringIdentity(s: string): string;
}
let { stringIdentity: id = arg => arg }: StringIdentity = { stringIdentity: x => x};
//// [contextuallyTypedBindingInitializer.js]
function f(_a) {
var _b = _a.show, show = _b === void 0 ? function (v) { return v.toString(); } : _b;
}
function ff(_a) {
var _b = _a.nested, nested = _b === void 0 ? { show: function (v) { return v.toString(); } } : _b;
}
function g(_a) {
var _b = _a.prop, prop = _b === void 0 ? ["hello", 1234] : _b;
}
function h(_a) {
var _b = _a.prop, prop = _b === void 0 ? "foo" : _b;
}
var _a = { stringIdentity: function (x) { return x; } }.stringIdentity, id = _a === void 0 ? function (arg) { return arg; } : _a;
@@ -0,0 +1,73 @@
=== tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializer.ts ===
interface Show {
>Show : Symbol(Show, Decl(contextuallyTypedBindingInitializer.ts, 0, 0))
show: (x: number) => string;
>show : Symbol(show, Decl(contextuallyTypedBindingInitializer.ts, 0, 16))
>x : Symbol(x, Decl(contextuallyTypedBindingInitializer.ts, 1, 11))
}
function f({ show = v => v.toString() }: Show) {}
>f : Symbol(f, Decl(contextuallyTypedBindingInitializer.ts, 2, 1))
>show : Symbol(show, Decl(contextuallyTypedBindingInitializer.ts, 3, 12))
>v : Symbol(v, Decl(contextuallyTypedBindingInitializer.ts, 3, 19))
>v.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
>v : Symbol(v, Decl(contextuallyTypedBindingInitializer.ts, 3, 19))
>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
>Show : Symbol(Show, Decl(contextuallyTypedBindingInitializer.ts, 0, 0))
interface Nested {
>Nested : Symbol(Nested, Decl(contextuallyTypedBindingInitializer.ts, 3, 49))
nested: Show
>nested : Symbol(nested, Decl(contextuallyTypedBindingInitializer.ts, 5, 18))
>Show : Symbol(Show, Decl(contextuallyTypedBindingInitializer.ts, 0, 0))
}
function ff({ nested = { show: v => v.toString() } }: Nested) {}
>ff : Symbol(ff, Decl(contextuallyTypedBindingInitializer.ts, 7, 1))
>nested : Symbol(nested, Decl(contextuallyTypedBindingInitializer.ts, 8, 13))
>show : Symbol(show, Decl(contextuallyTypedBindingInitializer.ts, 8, 24))
>v : Symbol(v, Decl(contextuallyTypedBindingInitializer.ts, 8, 30))
>v.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
>v : Symbol(v, Decl(contextuallyTypedBindingInitializer.ts, 8, 30))
>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
>Nested : Symbol(Nested, Decl(contextuallyTypedBindingInitializer.ts, 3, 49))
interface Tuples {
>Tuples : Symbol(Tuples, Decl(contextuallyTypedBindingInitializer.ts, 8, 64))
prop: [string, number];
>prop : Symbol(prop, Decl(contextuallyTypedBindingInitializer.ts, 10, 18))
}
function g({ prop = ["hello", 1234] }: Tuples) {}
>g : Symbol(g, Decl(contextuallyTypedBindingInitializer.ts, 12, 1))
>prop : Symbol(prop, Decl(contextuallyTypedBindingInitializer.ts, 13, 12))
>Tuples : Symbol(Tuples, Decl(contextuallyTypedBindingInitializer.ts, 8, 64))
interface StringUnion {
>StringUnion : Symbol(StringUnion, Decl(contextuallyTypedBindingInitializer.ts, 13, 49))
prop: "foo" | "bar";
>prop : Symbol(prop, Decl(contextuallyTypedBindingInitializer.ts, 15, 23))
}
function h({ prop = "foo" }: StringUnion) {}
>h : Symbol(h, Decl(contextuallyTypedBindingInitializer.ts, 17, 1))
>prop : Symbol(prop, Decl(contextuallyTypedBindingInitializer.ts, 18, 12))
>StringUnion : Symbol(StringUnion, Decl(contextuallyTypedBindingInitializer.ts, 13, 49))
interface StringIdentity {
>StringIdentity : Symbol(StringIdentity, Decl(contextuallyTypedBindingInitializer.ts, 18, 44))
stringIdentity(s: string): string;
>stringIdentity : Symbol(stringIdentity, Decl(contextuallyTypedBindingInitializer.ts, 20, 26))
>s : Symbol(s, Decl(contextuallyTypedBindingInitializer.ts, 21, 19))
}
let { stringIdentity: id = arg => arg }: StringIdentity = { stringIdentity: x => x};
>stringIdentity : Symbol(StringIdentity.stringIdentity, Decl(contextuallyTypedBindingInitializer.ts, 20, 26))
>id : Symbol(id, Decl(contextuallyTypedBindingInitializer.ts, 23, 5))
>arg : Symbol(arg, Decl(contextuallyTypedBindingInitializer.ts, 23, 26))
>arg : Symbol(arg, Decl(contextuallyTypedBindingInitializer.ts, 23, 26))
>StringIdentity : Symbol(StringIdentity, Decl(contextuallyTypedBindingInitializer.ts, 18, 44))
>stringIdentity : Symbol(stringIdentity, Decl(contextuallyTypedBindingInitializer.ts, 23, 59))
>x : Symbol(x, Decl(contextuallyTypedBindingInitializer.ts, 23, 75))
>x : Symbol(x, Decl(contextuallyTypedBindingInitializer.ts, 23, 75))
@@ -0,0 +1,85 @@
=== tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializer.ts ===
interface Show {
>Show : Show
show: (x: number) => string;
>show : (x: number) => string
>x : number
}
function f({ show = v => v.toString() }: Show) {}
>f : ({ show = v => v.toString() }: Show) => void
>show : (x: number) => string
>v => v.toString() : (v: number) => string
>v : number
>v.toString() : string
>v.toString : (radix?: number) => string
>v : number
>toString : (radix?: number) => string
>Show : Show
interface Nested {
>Nested : Nested
nested: Show
>nested : Show
>Show : Show
}
function ff({ nested = { show: v => v.toString() } }: Nested) {}
>ff : ({ nested = { show: v => v.toString() } }: Nested) => void
>nested : Show
>{ show: v => v.toString() } : { show: (v: number) => string; }
>show : (v: number) => string
>v => v.toString() : (v: number) => string
>v : number
>v.toString() : string
>v.toString : (radix?: number) => string
>v : number
>toString : (radix?: number) => string
>Nested : Nested
interface Tuples {
>Tuples : Tuples
prop: [string, number];
>prop : [string, number]
}
function g({ prop = ["hello", 1234] }: Tuples) {}
>g : ({ prop = ["hello", 1234] }: Tuples) => void
>prop : [string, number]
>["hello", 1234] : [string, number]
>"hello" : string
>1234 : number
>Tuples : Tuples
interface StringUnion {
>StringUnion : StringUnion
prop: "foo" | "bar";
>prop : "foo" | "bar"
}
function h({ prop = "foo" }: StringUnion) {}
>h : ({ prop = "foo" }: StringUnion) => void
>prop : "foo" | "bar"
>"foo" : "foo"
>StringUnion : StringUnion
interface StringIdentity {
>StringIdentity : StringIdentity
stringIdentity(s: string): string;
>stringIdentity : (s: string) => string
>s : string
}
let { stringIdentity: id = arg => arg }: StringIdentity = { stringIdentity: x => x};
>stringIdentity : any
>id : (s: string) => string
>arg => arg : (arg: string) => string
>arg : string
>arg : string
>StringIdentity : StringIdentity
>{ stringIdentity: x => x} : { stringIdentity: (x: string) => string; }
>stringIdentity : (x: string) => string
>x => x : (x: string) => string
>x : string
>x : string
@@ -0,0 +1,59 @@
tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts(4,20): error TS2322: Type '(v: number) => number' is not assignable to type '(x: number) => string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts(9,23): error TS2322: Type '{ show: (v: number) => number; }' is not assignable to type 'Show'.
Types of property 'show' are incompatible.
Type '(v: number) => number' is not assignable to type '(x: number) => string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts(14,23): error TS2322: Type '(arg: string) => number' is not assignable to type '(s: string) => string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts(19,14): error TS2322: Type '[number, number]' is not assignable to type '[string, number]'.
Types of property '0' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts(24,14): error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'.
Type '"baz"' is not assignable to type '"bar"'.
==== tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts (5 errors) ====
interface Show {
show: (x: number) => string;
}
function f({ show: showRename = v => v }: Show) {}
~~~~~~~~~~
!!! error TS2322: Type '(v: number) => number' is not assignable to type '(x: number) => string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
interface Nested {
nested: Show
}
function ff({ nested: nestedRename = { show: v => v } }: Nested) {}
~~~~~~~~~~~~
!!! error TS2322: Type '{ show: (v: number) => number; }' is not assignable to type 'Show'.
!!! error TS2322: Types of property 'show' are incompatible.
!!! error TS2322: Type '(v: number) => number' is not assignable to type '(x: number) => string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
interface StringIdentity {
stringIdentity(s: string): string;
}
let { stringIdentity: id = arg => arg.length }: StringIdentity = { stringIdentity: x => x};
~~
!!! error TS2322: Type '(arg: string) => number' is not assignable to type '(s: string) => string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
interface Tuples {
prop: [string, number];
}
function g({ prop = [101, 1234] }: Tuples) {}
~~~~
!!! error TS2322: Type '[number, number]' is not assignable to type '[string, number]'.
!!! error TS2322: Types of property '0' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
interface StringUnion {
prop: "foo" | "bar";
}
function h({ prop = "baz" }: StringUnion) {}
~~~~
!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'.
!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'.
@@ -0,0 +1,41 @@
//// [contextuallyTypedBindingInitializerNegative.ts]
interface Show {
show: (x: number) => string;
}
function f({ show: showRename = v => v }: Show) {}
interface Nested {
nested: Show
}
function ff({ nested: nestedRename = { show: v => v } }: Nested) {}
interface StringIdentity {
stringIdentity(s: string): string;
}
let { stringIdentity: id = arg => arg.length }: StringIdentity = { stringIdentity: x => x};
interface Tuples {
prop: [string, number];
}
function g({ prop = [101, 1234] }: Tuples) {}
interface StringUnion {
prop: "foo" | "bar";
}
function h({ prop = "baz" }: StringUnion) {}
//// [contextuallyTypedBindingInitializerNegative.js]
function f(_a) {
var _b = _a.show, showRename = _b === void 0 ? function (v) { return v; } : _b;
}
function ff(_a) {
var _b = _a.nested, nestedRename = _b === void 0 ? { show: function (v) { return v; } } : _b;
}
var _a = { stringIdentity: function (x) { return x; } }.stringIdentity, id = _a === void 0 ? function (arg) { return arg.length; } : _a;
function g(_a) {
var _b = _a.prop, prop = _b === void 0 ? [101, 1234] : _b;
}
function h(_a) {
var _b = _a.prop, prop = _b === void 0 ? "baz" : _b;
}
@@ -0,0 +1,25 @@
// @noImplicitAny: true
interface Show {
show: (x: number) => string;
}
function f({ show = v => v.toString() }: Show) {}
interface Nested {
nested: Show
}
function ff({ nested = { show: v => v.toString() } }: Nested) {}
interface Tuples {
prop: [string, number];
}
function g({ prop = ["hello", 1234] }: Tuples) {}
interface StringUnion {
prop: "foo" | "bar";
}
function h({ prop = "foo" }: StringUnion) {}
interface StringIdentity {
stringIdentity(s: string): string;
}
let { stringIdentity: id = arg => arg }: StringIdentity = { stringIdentity: x => x};
@@ -0,0 +1,25 @@
// @noImplicitAny: true
interface Show {
show: (x: number) => string;
}
function f({ show: showRename = v => v }: Show) {}
interface Nested {
nested: Show
}
function ff({ nested: nestedRename = { show: v => v } }: Nested) {}
interface StringIdentity {
stringIdentity(s: string): string;
}
let { stringIdentity: id = arg => arg.length }: StringIdentity = { stringIdentity: x => x};
interface Tuples {
prop: [string, number];
}
function g({ prop = [101, 1234] }: Tuples) {}
interface StringUnion {
prop: "foo" | "bar";
}
function h({ prop = "baz" }: StringUnion) {}