Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 777 Bytes

type-annotations-for-export-default.md

File metadata and controls

34 lines (23 loc) · 777 Bytes

export default 的类型注明

问题:

import * as webpack from 'webpack';
export default: webpack.Configuration {
    ...
};

这样写会报错。

答案:

import * as webpack from 'webpack'

export default {
    ...
} as webpack.Configuration

详见 microsoft/TypeScript#13626 (comment)

export default is bad in Typescript

export {default as X} from '...';

当别的库使用这个 X 会丢失类型,别的库识别到的是名为 default 的类型。应该是个 Bug。

其他理由: https://basarat.gitbook.io/typescript/main-1/defaultisbad (链接备份)