Reputation: 1408
I'm compiling my React/TypeScript app using tsc --build
and, while it worked well during development with TypeScript errors ignored, I'm encountering numerous errors in build mode. I initially attempted to suppress these errors, but I've realized I need to fix them instead.
However, I'm facing some particularly cryptic error messages, like the one below:
error TS2322: Type 'string' is not assignable to type '"button" | "submit" | "reset"'.
<button
type="button"
~~~~
node_modules/@types/react/index.d.ts:3148:9
3148 type?: "submit" | "reset" | "button" | undefined;
~~~~
The expected type comes from property 'type' which is declared here on type 'DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>'
It's not a matter of "Type X is not assignable to type X"; rather, it's complaining that I'm providing a string
type, which is larger than the required type. However, the actual type I'm providing is not a string
—it precisely matches the required type!
I'm adding a bunch of // @ts-ignore
as a workaround.
Could anyone help me understand the root cause of these errors? What might be causing TypeScript to produce such messages when the type actually matches?
Upvotes: 1
Views: 49
Reputation: 413
Definitely looks like an issue with your TypeScript setup somehow, and not the code, and it's kinda hard to give advice from afar.
Some options to try:
type=("button" as const)
or type=("button" as "button" | "submit" | "reset")
Upvotes: 2