导入没有 type 关键字的类型


\Importing types without type keyword

由于类型剥离的性质,type 关键字对于正确剥离类型导入是必需的。如果没有 type 关键字,Node.js 会将导入视为值导入,这将导致运行时错误。tsconfig 选项 verbatimModuleSyntax 可用于匹配此行为。

\Due to the nature of type stripping, the type keyword is necessary to correctly strip type imports. Without the type keyword, Node.js will treat the import as a value import, which will result in a runtime error. The tsconfig option verbatimModuleSyntax can be used to match this behavior.

此示例将正常工作:

\This example will work correctly:

import type { Type1, Type2 } from './module.ts';
import { fn, type FnParams } from './fn.ts'; 

这将导致运行时错误:

\This will result in a runtime error:

import { Type1, Type2 } from './module.ts';
import { fn, FnParams } from './fn.ts'; 

AltStyle によって変換されたページ (->オリジナル) /