frenic / csstype

Strict TypeScript and Flow types for style based on MDN data
MIT License
1.7k stars 69 forks source link

Export `DataType` #138

Closed j-m closed 2 years ago

j-m commented 2 years ago

I was wondering whether it'd be possible for the package to export its DataType namespace, please? Or is there a reason not to?

I think it'd be pretty useful, for example, I'm wanting to limit the prop values of alignItems and justifyContent to be just DataType.ContentPosition | DataType.ContentDistribution. The existing type doesn't really limit the prop values as it uses | string: export type JustifyContent = Globals | DataType.ContentDistribution | DataType.ContentPosition | "left" | "normal" | "right" | (string & {});

I had a quick search through the issues and only found this unanswered question:

Also, what's the rationale for not exporting the DataType namespace? Originally posted by @buschtoens in https://github.com/frenic/csstype/issues/131#issuecomment-881663122

frenic commented 2 years ago

Those data types receives its name from the spec. E.g. <color> becomes DataType.Color and <content-distribution> becomes DataType.ContentDistribution. It happens quite frequent that these data types are split into several data types or/and name changes as the spec develops. So there's a risk that a minor/patch update from csstype can break your typing if you're using the DataType namespace. But it's easily solved by updating the csstype dependency in package.json and change to the correct data type. So I can add a JSdoc comment about these risks and export it.

j-m commented 2 years ago

Makes sense. Sounds perfect, yes please!

paulorgl commented 2 years ago

@frenic do we already have a forecast of when this will be available for use?

frenic commented 2 years ago

Published in csstype@3.1.0