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.

Can't export typescript types for React props - Warning "export 'FooProps' was not found in './Foo'

See original GitHub issue

Describe the bug

I use typescript interfaces to prop-check my React components and I export them for later usage.

Foo.ts

export interface FooProps {
  bar: string;
}

export function Foo(props: FooProps) {
  return <div>{props.bar}</div>
}

index.ts

export { Foo, FooProps } from "./Foo";

Yields:

WARNING in ./src/components/Foo.ts 1:0-62
"export 'FooProps' was not found in './Foo'

To Reproduce Steps to reproduce the behavior:

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

I expect to have all Typescript types available for import.

Screenshots If applicable, add screenshots to help explain your problem.

Code snippets If applicable, add code samples to help explain your problem.

System Please paste the results of npx sb@next info here.

Environment Info:

  System:
    OS: Linux 3.10 Red Hat Enterprise Linux Server 7.9 (Maipo)
    CPU: (8) x64 Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz
  Binaries:
    Node: 10.19.0
    npm: 6.13.4
  Browsers:
    Chrome: 81.0.4044.138
  npmPackages:
    @storybook/addon-actions: ^6.1.11 => 6.1.11 
    @storybook/addon-knobs: ^6.1.11 => 6.1.11 
    @storybook/addons: ^6.1.11 => 6.1.11 
    @storybook/react: ^6.1.11 => 6.1.11 
    @storybook/storybook-deployer: ^2.8.7 => 2.8.7 

Additional context Add any other context about the problem here.

Edit:

Typescript 3.8 released a feature to mark type-only imports/exports by type to help the elision process. https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-beta/#type-only-imports-exports

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

27reactions
tommyc38commented, Dec 29, 2020

My issue was related to: https://github.com/webpack/webpack/issues/7378

I read this article: https://medium.com/javascript-in-plain-english/leveraging-type-only-imports-and-exports-with-typescript-3-8-5c1be8bd17fb

…then updated my code from:

//libs/core/src/lib/core/directives/background.directive.ts --line 2
import  {CorColorBackgroundType } from '@umbrelo/data';

To:

//libs/core/src/lib/core/directives/background.directive.ts --line 2
import type {CorColorBackgroundType } from '@umbrelo/data';

Now the warning is gone.

4reactions
AndyOGocommented, Jan 4, 2021

Typescript 3.8 released a feature to mark type-only imports/exports by type to help the elision process. https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-beta/#type-only-imports-exports

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Warning: Export, reexported as, was not found ...
Either way the solution is that your type needs to be exported differently. Updating your code to the following should fix your issue....
Read more >
Documentation - JSX - TypeScript
As the name suggests, the component is defined as a JavaScript function where its first argument is a props object. TS enforces that...
Read more >
Build a component library with React and TypeScript
Learn to create a component library with React and TypeScript in this in-depth tutorial that includes testing and deploying to npm.
Read more >
propTypes vs typescript types in React components - Medium
Prop types validate's react component's prop types in runtime and provide warnings in browser console if the sent prop is missing or the...
Read more >
Typechecking With PropTypes - React
import PropTypes from 'prop-types'; class Greeting extends React. ... PropTypes exports a range of validators that can be used to make sure the...
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