diff --git a/test/declarations/__snapshots__/export-variable-and-type-with-identical-name.test.ts.snap b/test/declarations/__snapshots__/export-variable-and-type-with-identical-name.test.ts.snap new file mode 100644 index 0000000..45d8dd8 --- /dev/null +++ b/test/declarations/__snapshots__/export-variable-and-type-with-identical-name.test.ts.snap @@ -0,0 +1,24 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`export variable and type with identical name 1`] = ` +[ + { + "docs": [], + "file": "/index.ts", + "id": "type-alias.foo", + "kind": "type-alias", + "line": 2, + "name": "foo", + "signature": "type foo = string | number;", + }, + { + "docs": [], + "file": "/index.ts", + "id": "variable.foo", + "kind": "variable", + "line": 3, + "name": "foo", + "signature": "const foo: { a: number };", + }, +] +`; diff --git a/test/declarations/export-variable-and-type-with-identical-name.test.ts b/test/declarations/export-variable-and-type-with-identical-name.test.ts new file mode 100644 index 0000000..70e0791 --- /dev/null +++ b/test/declarations/export-variable-and-type-with-identical-name.test.ts @@ -0,0 +1,37 @@ +import dedent from "ts-dedent"; +import { + ModuleKind, + ModuleResolutionKind, + Project, + ScriptTarget, +} from "ts-morph"; +import { expect, test } from "vitest"; +import { extractDeclarations } from "../../src"; + +test("export variable and type with identical name", async () => { + const project = new Project({ + useInMemoryFileSystem: true, + compilerOptions: { + lib: ["lib.esnext.full.d.ts"], + target: ScriptTarget.ESNext, + module: ModuleKind.ESNext, + moduleResolution: ModuleResolutionKind.Bundler, + }, + }); + const indexFile = project.createSourceFile( + "index.ts", + dedent` + // Similar to usage suggested with zod type inference. + export type foo = string | number + export const foo = { a: 1 }; + `, + ); + expect( + await extractDeclarations({ + containerName: "", + container: indexFile, + maxDepth: 5, + project, + }), + ).toMatchSnapshot(); +});