-
Notifications
You must be signed in to change notification settings - Fork 74
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
Improve the Flow type generator #67
Conversation
friendly ping @frenic |
Waw, I love this! Thank you! ❤️ First of, I'm not using Flow. So I'm hoping someone else with more Flow knowledge could do a review too. Maybe @rtsao? Is if there's a way to use missing vendor specific properties or custom properties concerning it's using exact types by default? How would you solve this? const css: CSS.Properties<*> = {
'--my-color': 'black',
}; This change should also be treated as a major change if I understand it correctly? |
@frenic If it's really required const css: { ...CSS.Properties<*> } = {
'--my-color': 'black',
}; |
Also this is equal to just export type AlignContentProperty = Globals | ContentDistribution | ContentPosition | "baseline" | "normal" | string; |
It's useless for TypeScript too and will most likely forever be useless for validation. But we're hoping that one day that tools like VSCode will provide autocompletion using these literals. There's an issue regarding this already. They are kept because there hasn't been any reason to remove them yet. No major performance benefits or anything like that since last time I checked. But the case could be different for Flow? |
You can change it to an inexact type as @TrySound mentioned, but I think it'd be better to define the custom properties in userland. Something like: type ColorVariables = {|
'--my-color': string,
'--my-color-2': string,
|};
function getSomeStyle(): {|...CSS.Properties<*>, ...$Shape<ColorVariables>|} {
...
} The nice thing about
Yeah, this would be a breaking change.
I actually didn't notice that |
|
Thanks @frenic. I think the potential gains of dropping the |
I did a quick check on a huge Typescript application using CSS-in-JS with csstype and there's not even a tiny performance difference when type checking between the latest release of csstype and the one with removed string literals. Typescript simplifies |
Thank you for this 👏 I'm merging this into separate branch as a part for v3. |
First of all, thank you for creating this library.
I made some changes to the Flow type generator:
@flow strict
. This allows@flow strict
projects to consume the type.{| ... |}
) by default. Now if you add an unknown property, Flow will warn. (See__tests__/__snapshots__/flow.ts.snap
)...
) instead of intersection types (&
). Intersection types are weird. We generally prefer using exact types and type spread. https://flow.org/en/docs/types/objects/#toc-exact-object-typesstring | string[]
) to the top of the file. Unfortunately there's a bug in Flow (Fix object spreading, issues 6108, 7242, 5243, 7210, 7253, 6357, 5253, 4682, 6800, 981, 7048 and more facebook/flow#7298) related to type spread and union types. An easy way to fix it is to lift the duplicated union types to type aliases.(here's the error if we don't lift the types)