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.

Triple slash directive is broken #469

See original GitHub issue

I saw that #469 issue was resolved by #472 and then changed by #482

For some reason I am now getting the error

[ts]
JSX element type 'MyComponent' is not a constructor function for JSX elements.
  Property 'setState' is missing in type 'MyComponent'.
[ts] JSX element class does not support attributes because it does not have a 'props' property.

The generated .d.ts file looks like the following:

declare module '@mycomponents/components' {
    import * as React from 'react';

    export interface MyComponentProps {
        children: React.ReactNode;
    }

    export default class MyComponent extends React.Component<MyComponentProps, any> {
        render(): JSX.Element;
    }
}

If I add

/// <reference types="react" />

Then this solves this issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
KnisterPetercommented, Dec 3, 2018

Thanks, I’ll look into it

1reaction
seawattscommented, Dec 3, 2018

Here is the component before it’s been compiled

// theme.js
import React from "react"
import PropTypes from "prop-types"
import { Provider, Consumer } from "./context"

class Theme extends React.Component {
  static propTypes = {
    tokens: PropTypes.objectOf(PropTypes.string),
    children: PropTypes.element,
  }

  static defaultProps = { tokens: {} }

  render() {
    const { children, tokens } = this.props
    return (
      <Consumer>
        {contextTokens => (
          <Provider value={{ ...contextTokens, ...tokens }}>
            {children}
          </Provider>
        )}
      </Consumer>
    )
  }
}

export default Theme

Here is the output type file

import * as React from 'react';

export interface ThemeProps {
    tokens?: any;
    children?: React.ReactElement<any>;
}

export default class Theme extends React.Component<ThemeProps, any> {
    render(): JSX.Element;
}

Then when trying to consume this library, I get the following error:

JSX element class does not support attributes because it does not have a 'props' property.ts(2607)
Type '{ children: Element; tokens: any; }' is not assignable to type '{}'.
  Property 'tokens' does not exist on type '{}'.ts(2322)

I have also tried to change the call to generateFromFile from

generateFromFile(null, `${path}/theme.js`)

to

generateFromFile('@mycomponents/theme', `${path}/theme.js`)

Where the later just wraps the entire file with

declare module '@mycomponents/theme' {
  import * as React from 'react';
  ...
}

Library versions:

Typescript: v3.2.1 react-to-typescript-definitions: v1.2.0 react: v16.6.3 vscode: Code - Insiders edition

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allowing relative paths in triple slash "types" directives ...
I managed to publish a module with unusable type definitions due to incorrect use of triple slash directives in one of my dependencies....
Read more >
Documentation - Triple-Slash Directives - TypeScript
Triple -slash directives are single-line comments containing a single XML tag. The contents of the comment are used as compiler directives.
Read more >
How to avoid ugly imports in TS Triple-Slash Directives
1 Answer 1 · ok so in the tsconfig.json I can... include the global.d.ts? · @Ckappo I edited. If you exclude something, all...
Read more >
State v. Robinson, 146 S.W.3d 469 | Casetext Search + Citator
As recounted in great detail above, with respect to premeditated murder, the evidence reasonably supports only one of the following conclusions: (1) Robinson ......
Read more >
NEMIS HMGP User Manual - Version 3 MR 19.01 - FEMA
NEMIS. The National Emergency Management Information System (NEMIS) is a database system used to track disaster data for FEMA and Recipient ...
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