-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Typescript fails to throw error when a generic is assigned to another generic of whom it's generic type is a superset #13970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
here's an even simpler example that doesn't require classes or interfaces
and using inference rather than explicit same thing:
|
code example without the generic to prove that normally a superset is unassignable
|
@gmoothart @evmar @bb @joshk @huerlisi sorry to ping you all. not sure who should take a look at this. seems like a pretty major bug. |
This is actually a result of structural compatibility and function parameter bivariance. Essentially when This is undesirable, but we're thinking about fixes. See this section in our FAQ for more details. |
@DanielRosenwasser ok :) i don't fully understand the terms you used but i think i get the gist. glad to hear it's being worked on :) |
The correct error should be reported with #15104. |
awesome!
…On Thu, 18 May 2017 at 09:53 Mohamed Hegazy ***@***.***> wrote:
The correct error should be reported with #15104
<#15104>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13970 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABE5mDzTMaRcBXRA2EtEyOC78AXJCYAXks5r7HdsgaJpZM4L72sH>
.
|
Sorry about that - that was a bit more jargon-y than I realized. 😄 |
hahahaha! best. thanks again for the fix :)
…On Thu, 18 May 2017 at 12:50 Daniel Rosenwasser ***@***.***> wrote:
@DanielRosenwasser <https://github.com/danielrosenwasser> ok :) i don't
fully understand the terms you used but i think i get the gist. glad to
hear it's being worked on :)
Sorry about that - that was a bit more jargon-y than I realized. 😄
[image: image]
<https://cloud.githubusercontent.com/assets/972891/26220693/7999d318-3bc8-11e7-9f79-44ad256789a9.png>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13970 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABE5mPC3p7xJ_KZahOLNexga_aW57F64ks5r7KD_gaJpZM4L72sH>
.
|
TypeScript Version: 2.1.4
Code
Expected behavior:
TS throws an error that MyClass incorrectly implements MyInterface
type
Promise<number | string | string[]>
not assignable toPromise<number | string>
otherwise a client using the class as
MyInterface
can call the method and only handle a return promise of string or number and have errors when the promise is resolved with the array.Actual behavior:
No error is thrown. (It's worth noting this doesn't repro without the generic. If for example the method were not async.) This also is not thrown if the return type is manually specified as
Promise<number | string | string[]>
just to be clear inference is not to blame.The text was updated successfully, but these errors were encountered: