下記の様な構成でTypeをimportしようと試みたのですが、エラーが出てうまくいかなかったのでご教示ください。
version
react: 16.8.6
TypeScript: 3.5.1
// フォルダ構成 /Parent |- Parent.tsx |- /Components |-/Child |-index.tsx |-Child.tsx
Child
1//Child.tsx 2 3export type childProps = { 4 title: string; 5 body: string; 6}; 7 8const Child: any = (props: childProps) => { 9 return( 10 <div></div> 11 ); 12}; 13 14export default Child; 15
index
1//index.tsx 2 3export { default, childProps } from './Child'; 4 5// childPropsにエラー 6// Cannot re-export a type when the '--isolatedModules' flag is provided.ts(1205) 7
Parent
1//Parent.tsx 2import { Child, childProps} from './components'; 3
index.tsxでエラーが出てしまいます。
childPropsをindex.tsxを介さずに、import { childProps } from './components/Child/Child'
といった形でimportすると、うまく行きます。
下記のリンクで出されてた対処法は試してみたものの、うまくいきませんでした。
型は直接importするしかないのでしょうか?
そもそも親と子で同じ型を使用したい場合には、子から親へimportする方法というのは正しいのでしょうか。
以上よろしくお願いします。
https://github.com/facebook/create-react-app/issues/6054
https://github.com/microsoft/TypeScript/issues/28481
あなたの回答
tips
プレビュー