-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Literal not contextually narrowed when returned from an abstract method #55318
Comments
I believe this to be a duplicate of #32082. |
@MartinJohns Interesting, it does seem related although it explicitly states:
It also seems like beyond the lack of literal narrowing here, the fact that the symbol type doesn't work even when cast seems worth addressing. |
This is more in spirit of #23911 - the method signature (both param and return type) should ideally be modified by the |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh I would love to have full parameter inference when extending a class, but a lot of my confusion around this was a lack of understanding how "fresh" literal references work, because my intuition was that the function should normally be inferred as returning the const type (which I still believe it probably should, but that seems unlikely to change). That said, the symbol case seems clearly to be distinct from the issue you mentioned- there is no question that if I explicitly cast the return type like that, it should be inferred that way like the literal types, right? Is there an existing issue for this? |
Symbol return type widening is tracked here. |
π Search Terms
symbol string number literal abstract narrow return class subclass
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/MYewdgzgLgBGCuBbGBeGBWAsAKFJW0ATqjAEQBmIIpOe0MEAnsmgMrMBGIANgBQCUOHAEMORYcFjBuwiBBgAhWQFMYAbxwwtMUeMkwA5sqisohAJZgDAgFxlK1Tdt1mJsI1ABySDssK2MJy0XQjdDY3ZELj5+OyhGAAdlEHIGZiCdMVd9DwBhWShlABNI6ID4pJS0xBwAXyFcGTkYXIALc24imGUAD0KwIvklCFUNbG0YAHpJmABRQkIQQjsAFUTVAHIiSwMNmHN5MBBYWQhzAzBRblUoEBgKzYoqUg2Mj1MLKwF1DInCY3ghDADDMGXq2Ay0zmCyWq3WMA2CCifj2Bzgxx0cnOlw413udweCPQr3G2g83mR-n4P1JEy0-yggOBSLBDQmUPmi2WWjWSQRTCiPFRhwxp2xVxuBPhG3gYHMAEd4KoBdESRN3pweN8xnTtAymdVWRDaVMZpzYTzpSqhfsRScsRcJfj7tLZQqldVVW9jPloMVSlrqTrdaaYKxzIgOsJCNxGDBgAUdiDiEs4EhnQ8qkQYKnM6kkTB-hAkpJzAA3ZSxmBFEDKeT-RAgCv3VqqPxcgA0DAJ7XkI2UiHktxgvhgbsVkpbys13HjKl+eoBQOqmJdlVSAqN4KAA
π» Code
π Actual behavior
Return types were not contextually narrowed and allowed.
π Expected behavior
Return types are contextually narrowed and allowed. Currently the best workaround is to add an explicit return annotation. Symbol case is possibly related to #53276, associated PR is #54778
The text was updated successfully, but these errors were encountered: