I'm working with React and Typescript, building a custom input component and I wish to cleanup the allowed values from type
attribute in the input
element to prevent unintended used as 'button' and 'hidden'.
The type
attribute have the type of HTMLInputTypeAttribute
that's an union type that ends up with (string & {})
. I don't want the component to receive type values that are not literal described in the union.
Using the Exclude
utility type results in never
since all literal types extends from string
I've already looked at other questions like How can I remove a wider type from a union type without removing its subtypes in TypeScript? but as their intent was not necessarily related to a previously established union, none of the answers met my need
Is this somehow possible?