question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TypeScript] Should reactHelpers functions be Type Guard or not?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
SSW-SCIENTIFICcommented, Dec 27, 2017

@pelotom Ok I understood, and open PR without type parameter soon.

1reaction
pelotomcommented, Dec 21, 2017

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 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found