无法从模块打字稿中找到导出
Can't find export from module typescript
获得了导出对象的文件:
let btypes:{[key:string]:any} = {
"key1":val,
//...
}
export {btypes}
我也试过了export default btypes
当我导入它时:
import {btypes} from "../types";
终端输出:
src/tests/parse.test.ts:3:8 - error TS1192: Module '"/abc/types"' has no default export.
或
src/tests/parse.test.ts:3:9 - error TS2305: Module '"../types"' has no exported member 'btypes'.
知道要在这里寻找什么吗?
尝试这样导出:
export default {btypes};
然后像这样导入:
import * as btypes from '../types';
他们说:in the playground (and also in the docs):
(...) there is a confusing part of default exports:/ Some exports have documentation that implies you can write an import like this: import req from "request";
However that fails, and then you find a stack overflow which recommends the import as: import * as req from "request";
这是@Mustafa 建议的默认导出。
操场上写了另一个解决方案。将此添加到 tsconfig.js:
- esModuleInterop:true
- allowSyntheticDefaultImports:true
现在import myDefaultExport from './myMod';
应该够了。
获得了导出对象的文件:
let btypes:{[key:string]:any} = {
"key1":val,
//...
}
export {btypes}
我也试过了export default btypes
当我导入它时:
import {btypes} from "../types";
终端输出:
src/tests/parse.test.ts:3:8 - error TS1192: Module '"/abc/types"' has no default export.
或
src/tests/parse.test.ts:3:9 - error TS2305: Module '"../types"' has no exported member 'btypes'.
知道要在这里寻找什么吗?
尝试这样导出:
export default {btypes};
然后像这样导入:
import * as btypes from '../types';
他们说:in the playground (and also in the docs):
(...) there is a confusing part of default exports:/ Some exports have documentation that implies you can write an import like this:
import req from "request";
However that fails, and then you find a stack overflow which recommends the import as:
import * as req from "request";
这是@Mustafa 建议的默认导出。
操场上写了另一个解决方案。将此添加到 tsconfig.js:
- esModuleInterop:true
- allowSyntheticDefaultImports:true
现在import myDefaultExport from './myMod';
应该够了。