-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7e7bb1
commit 0056760
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/typeArgumentInferenceWithObjectLiteral.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
}); |
65 changes: 65 additions & 0 deletions
65
tests/baselines/reference/typeArgumentInferenceWithObjectLiteral.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
}); | ||
|
18 changes: 18 additions & 0 deletions
18
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithObjectLiteral.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); |
0056760
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for the parentheses too, since you fixed that as well.
0056760
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can you add a test with multiple parameters, to test that all the parameters are visited first (without context sensitive), and then the context sensitive ones are revisited? Namely, if the first parameter is context sensitive, and the second is not, you want to infer from both, and then visit the context sensitive part of the first one.
Actually one further test. You infer a type from the context insensitive parts of each argument, and then you decide that the signature is not applicable so you never get to the context sensitive part.
0056760
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconded, these are good tests to have.