-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Object literal with variable property is overly generic #21030
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
Comments
The computed property doesn't take the union type - so it is widened to string. Simplified Example
|
Should be addressed by #21070 |
here is the sample using the unionize type: class BaseBlock<T extends keyof BV> {
readonly typeName: T;
value: BVTemplate<T>;
update(v: BV[T]) {
type union = {[P in T]: {[Q in P]: typeof v } }[T];
const updated: BVTemplate<T> = {
[this.typeName]: v,
} as union;
this.value = updated;
}
} |
more discussion in #18155 |
mhegazy
added
Design Limitation
Constraints of the existing architecture prevent this from being fixed
and removed
Bug
A bug in TypeScript
labels
Jan 9, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Code
Expected behavior:
typeName
isT
, but the type is incompatible with BVTemplate because the object literal declaration stores it asstring
.string
is not compatible toT
.Actual behavior:
I would hope this example could work. The commented string works perfectly, and in JS land those two things should be equivalent.
The text was updated successfully, but these errors were encountered: