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
This is working as intended. In readonlyNamedProp, the argument is contextually typed by { hello: string } (the constraint of T) which is taken as an indication that you want to infer a literal type for the hello property (i.e. some type that is a subtype of string). However, in readonlyObject there is no constraint and therefore no contextual type for the hello property, and since we're inferring for a mutable location we widen type 'World' to string.
TypeScript Version: 3.0.1
Search Terms
Code
TypeScript currently behaves inconsistently when declaring a
readonly
object directly in a function call.Expected behavior
Actual behavior
Example usage
I'm willing to use this on a Runtime Type Check library (still dirty code):
https://github.com/kube/structype
Current rework
Workaround is to wrap
kind
in a function call, which adds unnecessary verbosity:Playground Link
Related Issues
#10195
#14194
#20195
The text was updated successfully, but these errors were encountered: