[TypeScript] Should reactHelpers functions be Type Guard or not?
See original GitHub issueI have written typings to reactHelpers (#9565) but these functions (isMuiComponent
and isMuiElement
) are used for type checking.
So I think it is better to declare these functions as type guard.
By implementation,
export function isMuiElement(element: any, muiNames: Array<string>)
: element is ReactElement<P> & { type: { muiName: string } };
export function isMuiComponent<P>(element: any, muiNames: Array<string>): element is { muiName: string };
is considerable declaration (of course it looks not simple, so not good).
Is there any good type declaration for MUI element/component? or already exist? or the above functions should not be type guard (keep current, simply return boolean)?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (10 by maintainers)
Top Results From Across the Web
[TypeScript] Should reactHelpers functions be Type Guard or ...
I have written typings to reactHelpers (#9565) but these functions (isMuiComponent and isMuiElement) are used for type checking.
Read more >How to use type guards in TypeScript - LogRocket Blog
Type guards are regular functions that return a boolean, taking a type and telling TypeScript if it can be more specific.
Read more >Documentation - Advanced Types - TypeScript
A type guard is some expression that performs a runtime check that guarantees the type in some scope. Using type predicates. To define...
Read more >Type Guard - TypeScript Deep Dive - Gitbook
Here is a quick example where TypeScript realizes that a particular function does not exist on string and points out what was probably...
Read more >5 Methods to use Type Guards in TypeScript - Bits and Pieces
Type Guards come into the picture with the usage of TypeScript. This technique is used to identify or narrow down the type of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pelotom Ok I understood, and open PR without type parameter soon.
Oh! But obviously if you found it to have a certain name, then it definitely has that name. So it should not be optional. Re-corrected 😄