We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
multiple dynamic property types
Tried in those versions:
type IElement = { [P in keyof Record<any, any>]?: P extends "children" ? IElement[] : IElement; }; const element: IElement = { children: [{}, {}], something: {}, }; console.log(element);
type IElement = { children?: IElement[]; [key: string]?: IElement; }; const element: IElement = { children: [{}, {}], something: {}, }; console.log(element);
I hope that children: IElement[] type works
children: IElement[]
TS compiler can't identify children: IElement[] type, and just enforce to use only [key: string]: IElement type.
[key: string]: IElement
I can't sure this is a bug that TS compiler failed to detect multiple dynamic property types, or a spec do not allowing it.
The text was updated successfully, but these errors were encountered:
This is not currently possible. You want #17867
Sorry, something went wrong.
@fatcerberus Ah, this is called hybrid type. Thanks for your link.
No branches or pull requests
Bug Report
π Search Terms
multiple dynamic property types
π Version & Regression Information
Tried in those versions:
β― Playground Link
π» Code
1st way
2nd way
π Actual behavior
I hope that
children: IElement[]
type worksπ Expected behavior
TS compiler can't identify
children: IElement[]
type, and just enforce to use only[key: string]: IElement
type.I can't sure this is a bug that TS compiler failed to detect multiple dynamic property types, or a spec do not allowing it.
The text was updated successfully, but these errors were encountered: