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.

no-unused-prop-types is unable to parse type aliases

See original GitHub issue

no-unused-prop-types v.7.4.0 throws when trying to parse this code

type SomeProps = {};
type DefaultProps = SomeProps;
type Props = DefaultProps & {};
export class TestComponent extends React.Component<Props, void> {}
TypeError: Cannot read property 'length' of undefined
    at iterateProperties (eslint-plugin-react/lib/rules/no-unused-prop-types.js:336:21)
    at declarePropTypesForObjectTypeAnnotation (eslint-plugin-react/lib/rules/no-unused-prop-types.js:725:7)
    at propTypes.types.some.annotation (eslint-plugin-react/lib/rules/no-unused-prop-types.js:767:16)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
k15acommented, Oct 12, 2017

Yes, this is valid Syntax. You can read more about them here: https://flow.org/en/docs/types/typeof/

1reaction
jseminckcommented, Sep 25, 2017

Thanks for the report.

I did some quick digging and reproduced the issue. Additionally I found that the following code did parse correctly, but did not detect unused prop-types:

        type SomeProps = {
          firstname: string
        }
        type Props = SomeProps;
        export class TestComponent extends React.Component<Props, void> {
          render() {
            return <div>{this.props.foo}</div>
          }
        }

I have managed to get both cases working (your example + the above). I’ll try to get a PR in within the next few days (as I’m currently travelling a bit).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relax visibility rules for type-aliases when 'declaration ...
When using the declaration compiler option, this example fails to compile with the following error: error TS4078: Parameter 'fn' of exported ...
Read more >
Types: Type Aliases - HHVM and Hack Documentation
A type alias can be created in two ways: using type and newtype . ... meaning the including file cannot perform any integer-like...
Read more >
'type aliases' can only be used in a .ts file. TS8008 - Stack ...
Failed to compile. Type error: 'type aliases' can only be used in a .ts file. TS8008. That's because I have the following code...
Read more >
Documentation - TypeScript 4.2
TypeScript has a way to declare new names for types called type aliases. If you're writing a set of functions that all work...
Read more >
TypeScript | Type Aliases - Codecademy
In TypeScript, type aliases create type definitions, using the `type` keyword and a name, that can be reused throughout the code.
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