diff --git a/compute-type-value/evaluate.test.ts b/compute-type-value/evaluate.test.ts index 884f121..1851559 100644 --- a/compute-type-value/evaluate.test.ts +++ b/compute-type-value/evaluate.test.ts @@ -3,7 +3,7 @@ import * as fs from "node:fs"; import { describe, expect, it } from "vitest"; import { evaluate } from "./evaluate"; -describe("evaluate type", () => { +describe("evaluate type .ts", () => { it("standard", () => { const type = ` export type Handler = 1; @@ -46,3 +46,17 @@ describe("evaluate type", () => { expect(r2).toBe(1); }); }); + +describe("evaluate type .d.ts", () => { + it("standard", () => { + const type = ` + export type Handler = 1; + `.trim(); + const fileName = `/tmp/${randomUUID()}.d.ts`; + fs.writeFileSync(fileName, type); + + const result = evaluate(fileName, "Handler", {}); + + expect(result).toBe(1); + }); +}); diff --git a/compute-type-value/evaluate.ts b/compute-type-value/evaluate.ts index 96570ce..eeda3a3 100644 --- a/compute-type-value/evaluate.ts +++ b/compute-type-value/evaluate.ts @@ -3,18 +3,14 @@ import { type LiteralType, ModuleKind, NewLineKind, - NodeBuilderFlags, NodeFlags, - type PseudoBigInt, ScriptTarget, SyntaxKind, - TypeFormatFlags, createCompilerHost, createPrinter, createProgram, createSourceFile, factory, - isLiteralTypeNode, isTypeAliasDeclaration, } from "typescript"; @@ -43,7 +39,7 @@ function createMain( ), ]), ), - factory.createStringLiteral(entryFile), + factory.createStringLiteral(entryFile.replace(/\.[^/.]+$/, "")), ), factory.createTypeAliasDeclaration( undefined, diff --git a/compute-type-value/sampleIndex.ts b/compute-type-value/sampleIndex.ts index 4e6f442..bbce1ee 100644 --- a/compute-type-value/sampleIndex.ts +++ b/compute-type-value/sampleIndex.ts @@ -1,4 +1,4 @@ -import type { Sum } from "./sampleSum"; +import type { Sum } from "./sampleSum.d.ts"; type Event = { n1: number;