mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Adding test
This commit is contained in:
@@ -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; }
|
||||
});
|
||||
@@ -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
|
||||
|
||||
});
|
||||
|
||||
@@ -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
|
||||
});
|
||||
Reference in New Issue
Block a user