Adding test

This commit is contained in:
Anders Hejlsberg
2015-01-30 14:14:22 -08:00
parent c7e7bb12fe
commit 005676005f
3 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
//// [typeArgumentInferenceWithObjectLiteral.ts]
interface Computed<T> {
read(): T;
write(value: T);
}
function foo<T>(x: Computed<T>) { }
var s: string;
// Calls below should infer string for T and then assign that type to the value parameter
foo({
read: () => s,
write: value => s = value
});
foo({
write: value => s = value,
read: () => s
});
//// [typeArgumentInferenceWithObjectLiteral.js]
function foo(x) {
}
var s;
// Calls below should infer string for T and then assign that type to the value parameter
foo({
read: function () { return s; },
write: function (value) { return s = value; }
});
foo({
write: function (value) { return s = value; },
read: function () { return s; }
});

View File

@@ -0,0 +1,65 @@
=== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithObjectLiteral.ts ===
interface Computed<T> {
>Computed : Computed<T>
>T : T
read(): T;
>read : () => T
>T : T
write(value: T);
>write : (value: T) => any
>value : T
>T : T
}
function foo<T>(x: Computed<T>) { }
>foo : <T>(x: Computed<T>) => void
>T : T
>x : Computed<T>
>Computed : Computed<T>
>T : T
var s: string;
>s : string
// Calls below should infer string for T and then assign that type to the value parameter
foo({
>foo({ read: () => s, write: value => s = value}) : void
>foo : <T>(x: Computed<T>) => void
>{ read: () => s, write: value => s = value} : { read: () => string; write: (value: string) => string; }
read: () => s,
>read : () => string
>() => s : () => string
>s : string
write: value => s = value
>write : (value: string) => string
>value => s = value : (value: string) => string
>value : string
>s = value : string
>s : string
>value : string
});
foo({
>foo({ write: value => s = value, read: () => s}) : void
>foo : <T>(x: Computed<T>) => void
>{ write: value => s = value, read: () => s} : { write: (value: string) => string; read: () => string; }
write: value => s = value,
>write : (value: string) => string
>value => s = value : (value: string) => string
>value : string
>s = value : string
>s : string
>value : string
read: () => s
>read : () => string
>() => s : () => string
>s : string
});

View File

@@ -0,0 +1,18 @@
interface Computed<T> {
read(): T;
write(value: T);
}
function foo<T>(x: Computed<T>) { }
var s: string;
// Calls below should infer string for T and then assign that type to the value parameter
foo({
read: () => s,
write: value => s = value
});
foo({
write: value => s = value,
read: () => s
});