Javascript 为什么这个类型脚本导出未定义?

Javascript 为什么这个类型脚本导出未定义?,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,我正在尝试使用Typescript和React制作一个NPM包。(TSX) 我遵循,但试图使多个组件,而不是只有一个 当我尝试像这样导入我的模块时 import { HelloWorld } from 'tsx_lib' src / GoodbyeWorld.tsx HelloWorld.tsx index.ts index.d.ts 它显示为未定义 console.log(HelloWorld) //undefined 我的文件夹结构如下所示 import { Hell

我正在尝试使用Typescript和React制作一个NPM包。(TSX)

我遵循,但试图使多个组件,而不是只有一个

当我尝试像这样导入我的模块时

import { HelloWorld } from 'tsx_lib'
src /
   GoodbyeWorld.tsx
   HelloWorld.tsx
   index.ts
index.d.ts
它显示为未定义

console.log(HelloWorld) //undefined
我的文件夹结构如下所示

import { HelloWorld } from 'tsx_lib'
src /
   GoodbyeWorld.tsx
   HelloWorld.tsx
   index.ts
index.d.ts
这是文件

GoodbyeWorld.tsx

import * as React from 'react';
import { GoodbyeWorldProps } from '../index';

export default class GoodbyeWorld extends React.Component<any, any> {
  render() {
    return <div style={{ color: this.props.color }}>Goodbye world!</div>;
  }
}
import * as React from 'react';
import { HelloWorldProps } from '../index';

export default class HelloWorld extends React.Component<any, any> {
  render() {
    return <div style={{ color: this.props.color }}>Hello world!</div>;
  }
}
索引d.ts

export * from './HelloWorld';
export * from './GoodbyeWorld';
import * as React from 'react';

export interface HelloWorldProps extends React.Props<HelloWorld> {
  color: string;
}

export interface GoodbyeWorldProps extends React.Props<HelloWorld> {
  color: string;
}

declare module 'hello-world' {

}

declare module 'goodbye-world' {

}

export class HelloWorld extends React.Component<HelloWorldProps, any> {}
export class GoodbyeWorld extends React.Component<HelloWorldProps, any> {}
import*as React from'React';
导出接口HelloWorldProps扩展React.Props{
颜色:字符串;
}
导出接口goodbyeworldrops扩展React.Props{
颜色:字符串;
}
声明模块“hello world”{
}
声明模块“再见世界”{
}
导出类HelloWorld扩展React.Component{}
导出类GoodbyeWorld扩展React.Component{}

我做错了什么?
HelloWorld.tsx
中的导出默认类HelloWorld是默认导出

export*from./HelloWorld'
将不会通过默认导出

您有两个选择:

  • HelloWorld.tsx导出名
  • 将默认导出映射到命名导出

  • 尝试从“tsx_lib”导入HelloWorld(不带括号)
    ,如果将其导出为
    default
    module,则需要导入它(不带括号),但我不尝试将其导出为默认值,我希望能够访问HelloWorld和GoodbyeWorld