격리 선언(Isolated Declarations) 출력
Oxc 트랜스포머는 isolated declarations가 켜진 프로젝트에서 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,
});
console.log(result.code); // .d.ts 내용
console.log(result.map); // 소스 맵(sourcemap이 켜진 경우)
console.log(result.errors); // 파싱·변환 오류같은 시그니처의 동기 isolatedDeclarationSync도 있습니다.