独立声明输出
Oxc 转换器支持在启用 独立声明 的项目中,无需使用 TypeScript 编译器即可输出 TypeScript 声明。
示例
输入:
ts
export function foo(a: number, b: string): number {
return a + Number(b);
}
export enum Bar {
a,
b,
}输出:
ts
export declare function foo(a: number, b: string): number;
export declare enum Bar {
a = 0,
b = 1,
}使用方法
ts
import { isolatedDeclaration } from "oxc-transform";
const result = await isolatedDeclaration("lib.ts", sourceCode, {
sourcemap: false,
stripInternal: false,
});