microsoft / microsoft/TypeScript
Cannot find type definition file for ambient declaration module
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.6 to 3.8.0-dev.20191025
Search Terms: ambient module triple slash reference path declaration
Code
// A *self-contained* demonstration of the problem follows...
[typings/somemodule/index.d.ts]
declare module "somemodule"
{
export namespace common {
export interface Foo {
bar: string;
fuzz: Number;
}
}
}
[src/index.ts]
/// <reference path="../typings/somemodule/index.d.ts" />
Typescript 3.5.3 works as expected, anything at or above 3.6 has the same issue..
When running tsc -d, for a manually created declaration file, the triple slash reference path file should be preserved in the output declaration file. This particular declaration file acts as a shim for an existing library whose type definitions are incomplete and is to be included as-is and without transpiler manipulation in the output declaration file. This provides accurate intellisense for package consumers and ensures build errors do not occur.
Expected behavior:
Maintain the same triple-slash reference path in the .d.ts file as was in the .ts file.
[dist/index.d.ts]
/// <reference path="../typings/somemodule/index.d.ts" />
Actual behavior:
The reference path is changed to reference types and the relative path is also broken:
[dist/index.d.ts]
/// <reference types="typings/somemodule" />
This causes consuming applications of the package to receive the following build error:
Cannot find type definition file for 'typings/somemodule'.
I have been unsuccessful in manipulating the consuming application to build correctly or provide correct intellisense with the updated directive. The original directive must be preserved.
Playground Link:
Related Issues: I believe this is where the issue was introduced: #32878
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with tsc -d using src/index.ts and typings/somemodule/index.d.ts, then compare the generated dist/index.d.ts with the expected triple-slash reference. Read the related issue #32878 and trace the declaration emit behavior responsible for converting the path reference. Done means the original reference path is preserved and consuming applications no longer report the missing type definition file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100