Skip to content
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

TypeScript Omit with StrictReactDOMProps results into empty object #113

Open
efoken opened this issue May 6, 2024 · 8 comments
Open

TypeScript Omit with StrictReactDOMProps results into empty object #113

efoken opened this issue May 6, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@efoken
Copy link

efoken commented May 6, 2024

Describe the issue

When using Omit in TypeScript it seems to omit everything. Example:

export interface IconButtonProps extends Omit<React.ComponentProps<typeof html.button>, "children"> {
  children: React.ReactElement<IconProps>;
}

This results in IconButtonProps type having the ONLY children, and some stuff from ReactStrictDOMDataProps, but nothing else. Every other prop, coming from html.button is also omitted. When removing the Omit<...> everything works fine.

This is maybe a bug with Flow to TypeScript conversion?

Expected behavior

Omitting props should only omit what is wanted.

Steps to reproduce

  1. Have react-strict-dom with TypeScript set up.
  2. Create IconButton.tsx containing the above example code.
  3. See that the interface only contain children
Screenshot 2024-05-06 at 17 45 24

Test case

No response

Additional comments

No response

@efoken efoken added the bug Something isn't working label May 6, 2024
@efoken
Copy link
Author

efoken commented May 6, 2024

Probably has to do something with ReactStrictDOMDataProps in TypeScript, which is not defined at all. If I define it inside dist/types/StrictReactDOMProps.d.ts, everything works as expected.

I just added:

type ReactStrictDOMDataProps = {}

@efoken
Copy link
Author

efoken commented May 11, 2024

Just found out that also Stringish is unresolved in TypeScript, which makes totally sense because it's converted from Flow.

I guess both Strinish and ReactStrictDOMDataProps should be interfaces. So that they can be overridden by TypeScript users, e.g. with data-props that are used in their projects.

@necolas
Copy link
Contributor

necolas commented May 12, 2024

I think TypeScript has a feature where it ignores any data-* props. It's something the Flow team is considering too. Ignoring ReactStrictDOMDataProps altogether for TypeScript might possible / better. Open to suggestions on how to manage Stringish better too

@efoken
Copy link
Author

efoken commented May 12, 2024

Yes exactly, TypeScript ignores all props in JSX containing - dashes

@nmn
Copy link
Contributor

nmn commented May 21, 2024

@necolas I still think that having these types exported from files gives us the most flexibility. We can override particular files for TS easily that way.

@necolas
Copy link
Contributor

necolas commented May 21, 2024

Sure. TS doesn't even need that file though

@efoken
Copy link
Author

efoken commented May 22, 2024

Can you just strip those types in TS? Replace ReactStrictDOMDataProps with {} and Stringish with string

@nmn
Copy link
Contributor

nmn commented May 22, 2024

@necolas Our tooling can only split on a file level, so having those files for TS where they're just aliased to {} and string as @efoken suggested is the easiest path. I'll create a PR so we can consider it with a real example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants