skovy / typed-scss-modules

🎁 Generate type definitions (.d.ts) for CSS Modules using SCSS
https://skovy.dev/generating-typescript-definitions-for-css-modules-using-sass/
MIT License
638 stars 67 forks source link

Feature request: allow unique types #211

Open angrybacon opened 1 year ago

angrybacon commented 1 year ago

In order to enforce specific type usage for my React components I'd like to output unique typings with the library.

For context, I use typed-scss-modules to output types for some of the re-usable values declared in SCSS. And the idea would be to enforce my component props use those specifically. Doing so would also enable completions for most IDE when completing said props.

Since outputting enums would be a bit more work and since they are a more controversial option, how about having the possibility to output unique symbols rather than plain strings through options?

const classNameToNamedTypeDefinition = (
  className: ClassName,
  uniqueSymbol: boolean
) => {
  const uniqueTyping = uniqueSymbol ? " & { readonly '': unique symbol }" : '';
  return `export declare const ${className}: string${uniqueTyping};`;
};
skovy commented 1 year ago

interesting, i haven't seen this approach used for unique typings before

conceptually, i like the idea and understand what you're going for. from a maintenance standpoint, i'm on the fence if i'd want this code to live in the library and need to maintain it.

what if this class name to type def function was exposed as a config option that could override the default? this way when the next person wants to customize the type output we don't need to add another configuration and more code, or if TypeScript it's proper support for unique types with this hack then this library wouldn't need to change.