You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior:
The code is valid and compiles without warning, because interface Foo contains a signature for a method foo corresponding to each type in the union string|string[]. The foo method can accept a parameter list of string, and it can also accept a parameter list of string[], therefore an argument list of string|string[] is satisfiable.
I would expect the return type for foo.foo invoked in this faction to be the type union of the return types of all matching signatures (so string|string[]). This code produces the same error even if all matching signatures have the same return type.
Actual behavior: Argument of type 'string | string[]' is not assignable to parameter of type 'string[]' Type 'string' is not assignable to type 'string[]'.
The text was updated successfully, but these errors were encountered:
you can also find a long discussion on why { foo(string|string[]):string|string[] } is not the same as { foo (string): string; foo (string[]): string[]; } at #7230. This should help shedding some light on how the API should be authored.
Maybe this is a degenerate case, but I feel like this instance should be satisfiable.
I feel like defining the interface this way is preferrable, because we can preserve the mapping for string->string and string[]->string[]. Passing in a parameter that matches both should simply result in string|string[]->string|string[]. Being less specific in what is passed in results in a result that is less specific, and vice versa.
In my actual code, both methods return void, so there really is no ambiguity; still, this is unsupported.
My actual code I'm using chrome.storage.StorageArea.remove, which can accept a string or string[]. I have keys which can be string or string[], so it's perfectly valid to pass it in; just the typings disagree with me.
TypeScript Version:
nightly (1.9.0-dev.20160303)
Code
Expected behavior:
The code is valid and compiles without warning, because interface
Foo
contains a signature for a methodfoo
corresponding to each type in the unionstring|string[]
. Thefoo
method can accept a parameter list ofstring
, and it can also accept a parameter list ofstring[]
, therefore an argument list ofstring|string[]
is satisfiable.I would expect the return type for
foo.foo
invoked in this faction to be the type union of the return types of all matching signatures (sostring|string[]
). This code produces the same error even if all matching signatures have the same return type.Actual behavior:
Argument of type 'string | string[]' is not assignable to parameter of type 'string[]' Type 'string' is not assignable to type 'string[]'.
The text was updated successfully, but these errors were encountered: