{"record":{"id":"0eed2994ee7965b9","repo":"sveltejs/kit","slug":"using-lib-file-instead-of-generated-d-ts-file","errorCode":null,"errorMessage":"Using $lib/${file} instead of generated .d.ts file","messagePattern":"Using \\$lib/(.+?) instead of generated \\.d\\.ts file","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/package/src/typescript.js","lineNumber":59,"sourceCode":"\t\t\t? require.resolve('svelte2tsx/svelte-shims-v4.d.ts')\n\t\t\t: require.resolve('svelte2tsx/svelte-shims.d.ts'),\n\t\tdeclarationDir: tmp,\n\t\ttsconfig\n\t});\n\n\tconst handwritten = new Set();\n\n\t// skip files that conflict with hand-written .d.ts\n\tfor (const file of files) {\n\t\tif (file.name.endsWith('.d.ts')) {\n\t\t\thandwritten.add(file.name);\n\t\t}\n\t}\n\n\t// resolve $lib alias (TODO others), copy into package dir\n\tfor (const file of walk(tmp)) {\n\t\tif (handwritten.has(file)) {\n\t\t\tconsole.warn(`Using $lib/${file} instead of generated .d.ts file`);\n\t\t}\n\n\t\tlet source = fs.readFileSync(path.join(tmp, file), 'utf8');\n\t\tif (file.endsWith('.d.ts.map')) {\n\t\t\t// Because we put the .d.ts files in a temporary directory, the relative path needs to be adjusted\n\t\t\tconst parsed = JSON.parse(source);\n\t\t\tif (parsed.sources) {\n\t\t\t\tparsed.sources = /** @type {string[]} */ (parsed.sources).map((source) =>\n\t\t\t\t\tposixify(\n\t\t\t\t\t\tpath.join(\n\t\t\t\t\t\t\tpath.relative(\n\t\t\t\t\t\t\t\tpath.dirname(path.join(final_output, file)),\n\t\t\t\t\t\t\t\tpath.dirname(path.join(input, file))\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tpath.basename(source)\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/package/src/typescript.js#L41-L77","documentation":"svelte-package generates .d.ts files into a temp directory and then copies them into the package, applying the $lib alias. If a generated declaration file collides with a handwritten .d.ts the user placed in the source tree (tracked in the `handwritten` set), it warns that the handwritten $lib/<file> version is being used instead of the generated one, so the generated types for that file are discarded.","triggerScenarios":"Running `svelte-package` (emit_dts) when a hand-authored .d.ts file in src/lib has the same output path as a file TypeScript would generate (e.g. src/lib/utils/index.d.ts alongside src/lib/utils/index.js).","commonSituations":"Manually maintained ambient/handwritten declarations left over after converting JS to TS; intentionally hand-written types that shadow generated ones after adding a matching .js/.ts file; stale .d.ts files committed to the repo before a build-tool migration.","solutions":["Delete the handwritten .d.ts file if it duplicates a .js/.ts source and let svelte-package generate types","Rename or move the handwritten declarations to a non-colliding path","Regenerate types and diff the generated output against the handwritten file to reconcile them"],"exampleFix":"// before: both src/lib/utils/index.js and src/lib/utils/index.d.ts exist\n// after: delete src/lib/utils/index.d.ts and import types from the generated output","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst generated = 'src/lib/utils/index.d.ts';\nif (fs.existsSync(generated) || fs.existsSync(generated.replace('.d.ts', '.js'))) {\n  console.warn('handwritten .d.ts will shadow generated types');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep at most one type source per module: either .js+.d.ts or .ts","Delete stale handwritten .d.ts files after TS migration","Run svelte-package and review warnings in CI"],"tags":["typescript","packaging","declaration-files"],"backgroundTag":"duplicate-dts-shadowing","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}