Document the MyTypes global namespace pattern#306
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new "Types global namespace" section to the documentation, detailing the use of the MyTypes module for shared ambient type declarations. Feedback suggests avoiding shorthand module declarations to prevent type safety issues, consolidating this new section with existing documentation to avoid redundancy, and refining type aliases to remove redundant wrappers and improve naming clarity.
| The `MyTypes` module is a shared namespace that lets each feature own its local | ||
| types while still contributing to a central app-level contract. | ||
|
|
||
| - `playground/typings/modules.d.ts` declares the ambient module name. |
There was a problem hiding this comment.
The use of a shorthand module declaration (e.g., declare module 'MyTypes';) in modules.d.ts is discouraged for internal type namespaces. Shorthand declarations make all imports from that module any, which bypasses type checking for missing or misspelled types. It is better to use an explicit (even if empty) module declaration: declare module 'MyTypes' {}.
| The `MyTypes` module is a shared namespace that lets each feature own its local | ||
| types while still contributing to a central app-level contract. | ||
|
|
||
| - `playground/typings/modules.d.ts` declares the ambient module name. |
|
|
||
| [⇧ back to top](#table-of-contents) | ||
|
|
||
| ### Types global namespace |
There was a problem hiding this comment.
| import { StateType, ActionType } from 'typesafe-actions'; | ||
|
|
||
| declare module 'MyTypes' { | ||
| export type Store = StateType<typeof import('./store').default>; |
There was a problem hiding this comment.
| declare module 'MyTypes' { | ||
| export type Store = StateType<typeof import('./store').default>; | ||
| export type RootAction = ActionType<typeof import('./root-action').default>; | ||
| export type RootState = StateType<ReturnType<typeof import('./root-reducer').default>>; |
There was a problem hiding this comment.
The use of ReturnType inside StateType is redundant. StateType from typesafe-actions automatically extracts the return type when a function (like a reducer) is passed.
| export type RootState = StateType<ReturnType<typeof import('./root-reducer').default>>; | |
| export type RootState = StateType<typeof import('./root-reducer').default>; |
|
|
||
| [⇧ back to top](#table-of-contents) | ||
|
|
||
| ### Types global namespace |
|
Addressed the highest-priority namespace feedback in this branch update. The example now uses an explicit empty |
Closes #97
Summary
MyTypesglobal namespace patternmodules.d.ts,store/types.d.ts, andservices/types.d.tswork togetherValidation
npm run ci-checkcd playground && npm run tsc