typed-scss-modules
typed-scss-modules copied to clipboard
Feature request: allow unique types
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 enum
s 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 string
s through options?
const classNameToNamedTypeDefinition = (
className: ClassName,
uniqueSymbol: boolean
) => {
const uniqueTyping = uniqueSymbol ? " & { readonly '': unique symbol }" : '';
return `export declare const ${className}: string${uniqueTyping};`;
};
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.