microsoft / microsoft/TypeScript
Incorrect error message on export assignment in `.d.ts` file
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.5.3
Search Terms:
An export assignment cannot be used in a namespace.
Code
This is pretty niche, but I think it has general implications...
The current /lib/typescript.d.ts file is modelled as essentially a CommonJS file where at the end of the file, it has export = ts; which exports the whole namespace. The actual /lib/typescript.js though will place itself in the global scope as ts if it isn't loaded as a CommonJS module. In order to express that ts is available as a global variable, it requires code like this to be placed in a .d.ts file:
import * as _ts from "typescript";
declare global {
namespace ts {
export = _ts;
}
}
Other methods of expressing this, like declare var ts: typeof _ts; only make the function shape of ts available, while the interfaces and type aliases and other type information is not accessible.
Expected behavior:
No errors.
Actual behavior:
The error TS1063: An export assignment cannot be used in a namespace occurs, but in VSCode, if the file is named globals.d.ts this error does not occur. 🤷♂ In all cases the code above does work like expected, making both the functional and type exports of the namespace available for code to be checked against.
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
Start by reproducing the diagnostic with the provided declaration snippet, then compare it with the behavior when the file is named globals.d.ts. Read the related declarations in /lib/typescript.d.ts and runtime context in /lib/typescript.js. Done means the valid pattern reports no error while retaining both functional and type exports.
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
- 42/100