TypeScript Type Error When Using useQueryState With String Union Types #1244
-
|
Hi, I'm running into a TypeScript issue when trying to use Code Snippet Causing the Issueexport type ViewMode = "list" | "grid" | "compact";
const [viewMode, setViewMode] = useQueryState<ViewMode>("view", {
defaultValue: "list",
});
The IssueTypeScript throws errors around the generic type parameter passed to My Questions
If you need more context, I can provide the full component or the type error logs. Thanks in advance! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
You should use Passing in a generic type cast is a form of "lying to TypeScript", as the runtime will still accept any string value, it's up to the parsers to implement the basic query value validation to conform to the type they describe. |
Beta Was this translation helpful? Give feedback.
You should use
parseAsStringLiteral.Passing in a generic type cast is a form of "lying to TypeScript", as the runtime will still accept any string value, it's up to the parsers to implement the basic query value validation to conform to the type they describe.