-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Default values of object destructuring of Generic type #30628
Comments
Hi @jack-williams |
I don't understand your use-case fully but I would write something like: const Header = <H extends HeaderTypes>(props: HeaderProps<H>) => {
const { abc = 'h1' }: HeaderProps<H | "h1"> = props;
// ......
} |
In my current context, it is ok. Thank you. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Hi, TypeScript Team
Version: 3.3.4
I have a problem with default values of destructed variables inside a generic function. If I don't specify type for destructuring construction I could set anything as default values.
Expected behavior:
abc can be assigned to 'h1'
Actual behavior:
TS2322:Type 'h1' is not assignable to type 'H'
Playground Link: example
The text was updated successfully, but these errors were encountered: