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

Type inference of Omit type not working, CSSProperties in preact/compat #4427

Closed
MTtankkeo opened this issue Jun 29, 2024 · 3 comments
Closed
Labels

Comments

@MTtankkeo
Copy link

MTtankkeo commented Jun 29, 2024

import { CSSProperties } from "preact/compat";

interface ExampleProperties extends Omit<CSSProperties, "display"> {
    // ... skip propertys

    [key: string]: any;
}

This issue is not present in react, In the code above, the auto-completion function of Sample Properties (which seems to be a type inference problem) is not working.

Of course, if you don't use Omit, type inference of the CSSProperties is working.

@rschristian
Copy link
Member

rschristian commented Jun 29, 2024

This is a TypeScript "issue" (technically working as intended, "limitation" might be a better word), not a Preact issue. See: microsoft/TypeScript#49656. I don't think forming our types in precisely the same way to get around limitations in TS is really within the scope of compat. At that point you might be better off trying to use React's types.

However, you can use something like this instead:

type MyOmit<T, K extends PropertyKey> = { [P in keyof T as Exclude<P, K>]: T[P] }

interface ExampleProperties extends MyOmit<CSSProperties, 'display'> {
    [key: string]: any;
}

@MTtankkeo
Copy link
Author

thanks, and that has helped me a lot.

@rschristian
Copy link
Member

Oh, and as I forgot to link it, here's a StackOverflow post that I swiped that impl from with a bit more context: https://stackoverflow.com/a/76616671/8963648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants