Hey. In Typescript I want to export eg. Select and its connected component eg. SelectOption. Want to be able to import it as import { Select } from 'select' and use as <Select><Select.Option>Test</Select.Option></Select>
How to do it and keep TS compiling without errors?
Matt Strom
Software Engineer, TypeScript ninja
Exporting a class should be as easy as
export class Select extends React.Component<Props, object> { } export class SelectOption extends React.Component<Props, object> { }And importing should be as easy as
import { Select, SelectOption } from './select'; <Select><SelectOption>Test</SelectOption></Select>Your problem may be that you are referring to the module with a package name rather than a path: 'select' versus './select'. Generally only Node modules can be referred to directly by name and without a path.
It may also be that in the TSX portion you are referring to the
SelectOptioncomponent withSelect.Option. Don't use the period in the component tag name.You may also not have your module system configured correctly. To use modules on the browser you need to use something like SystemJS, RequireJS, or Webpack.
Can you perhaps provide a more detailed code snippet? Your explanation does not provide enough detail.