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
{{ message }}
Repository navigation
Interface with methods interferes with string literal type inference #19497
This is a design limitation and is working as intended. See #10676 for context. In the original example we can't tell that T is used only in output positions within Observable<T>. Therefore we widen from 'a' to string. As you point out, you can force the desired result by writing 'a' as 'a'. It would be nice to do better here, but it isn't clear how we could cheaply and consistently determine that a type parameter is used only in output positions.
Kevin Donnelly (@kpdonn) The Observable in my example was actually from a library, so I can't change its declaration. Hopefully someone else will find that useful, though.
[I've since had to rewrite the code that had this issue for other reasons, this is not currently a problem for me any more.]
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
ahejlsberg commentedon Oct 26, 2017
This is a design limitation and is working as intended. See #10676 for context. In the original example we can't tell that
Tis used only in output positions withinObservable<T>. Therefore we widen from'a'tostring. As you point out, you can force the desired result by writing'a' as 'a'. It would be nice to do better here, but it isn't clear how we could cheaply and consistently determine that a type parameter is used only in output positions.ahejlsberg commentedon Oct 26, 2017
Andy (Andrewkraft) (@Andy-MS) Your example is working as it should. Array elements are mutable locations so widening is to be expected.
kpdonn commentedon Nov 1, 2017
Wolfgang Faust (@wolfgang42) Another potential workaround for your example if you are only expecting strings is:
wolfgang42 commentedon Nov 1, 2017
Kevin Donnelly (@kpdonn) The Observable in my example was actually from a library, so I can't change its declaration. Hopefully someone else will find that useful, though.
[I've since had to rewrite the code that had this issue for other reasons, this is not currently a problem for me any more.]
typescript-bot commentedon Nov 21, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.