Actions may not have an undefined 'type' property. Have you misspelled a constant? – Redux action creator
0 reputation · 04 Aug 2021, 16:06 UTC
0 reputation · 04 Aug 2021, 16:06 UTC
The goal is to decide whether Redux should rely primarily on its runtime warning for missing action types or adopt compile‑time guarantees (e.g., TypeScript‑based action schemas) as the main safety mechanism.
Constraints include preserving backward compatibility with existing JavaScript codebases, avoiding extra runtime overhead or bundle size increase, and ensuring a smooth developer experience for teams with varying TypeScript adoption.
Should Redux core enforce action‑type validation at compile time via TypeScript?
What impact would adding a compile‑time check have on bundle size and backward compatibility?
What steps are needed for existing projects to adopt compile‑time guarantees without breaking current action creators?
Redux core should not enforce action-type validation at compile time via a mandatory change to the library itself, as TypeScript is an external tool. Instead, it should continue to provide runtime warnings for JavaScript users while providing first-class type definitions that allow TypeScript users to opt into compile-time guarantees.
Implementing compile-time checks via TypeScript has the following effects:
To transition from runtime warnings to compile-time guarantees without breaking current action creators, follow these steps:
type property is always present.as const to ensure TypeScript treats them as literal strings rather than generic strings.return statements or misspelled properties.strict: true is set in tsconfig.json to prevent undefined from being passed as a type.To provide a more specific migration path, please clarify if your project is currently using a build tool that supports TypeScript (e.g., Vite, Webpack) or if you are relying on a pure JavaScript environment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.