Skip to content

Prop types don't match runtime types #2338

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

Closed
KaelWD opened this issue Oct 8, 2020 · 3 comments · Fixed by #2401
Closed

Prop types don't match runtime types #2338

KaelWD opened this issue Oct 8, 2020 · 3 comments · Fixed by #2401

Comments

@KaelWD
Copy link
Contributor

KaelWD commented Oct 8, 2020

Version

3.0.0

Reproduction link

https://codepen.io/kaelwd/pen/oNLgNGe?editors=1010

Steps to reproduce

Use boolean props in a typescript component

What is expected?

Boolean props should have type boolean, as their default default value is false

What is actually happening?

All non-required props without a default value are T | undefined


component.test-d.ts uses required: true to strip the undefined, but this is incorrect as boolean props aren't necessarily required. There are no checks for non-required boolean props.

Changing RequiredKeys to

type RequiredKeys<T> = {
  [K in keyof T]: T[K] extends { required: true } | { default: any } | BooleanConstructor | { type: BooleanConstructor } ? K : never
}[keyof T]

fixes it but seems wrong as they aren't actually required. default is in there already so whatever.

@wxk6b1203
Copy link

Yet another reproduction

Version
3.0.0-0

Reproduction link
https://gist.github.com/wxk6b1203/66914efbb633897655f525af9e4f3140

What is expected?
The default value specification at L 33 could be omitted.

What is actually happening?
If the default value at L 33 was deleted, the computed below shows that the overload not match.

@JensDll
Copy link
Contributor

JensDll commented Oct 16, 2020

I'm also having a lot of problems with props in TypeScript.

Version
3.0.1

Reproduction link
TS Playground - Examples at the bottom

@yyx990803
Copy link
Member

@JensD98 please open a separate issue since it's a different problem.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants