google / google/closure-compiler
How to make externs for npm packages without global pollution
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I want to use Closure Compiler to type check for a Node.js project (with CommonJS or ES Module).
It uses many npm packages and they need their externs files for type checking.
Can I make and provide externs for them?
I cannot make it because `module` is not available in externs.
sample: https://github.com/teppeis-sandbox/closure-node-sample1/tree/comment-out-require
Also `contrib/nodejs/*.js` doesn't work for the same reason.
I found a workaround using a global object like [react-externs](https://github.com/steida/react-externs), but it doesn't match the style of Node.
TypeScript supports for this feature with [ambient modules](https://www.typescriptlang.org/docs/handbook/modules.html#ambient-modules) in `d.ts`.
```typescript
declare module "path" {
export function normalize(p: string): string;
export function join(...paths: any[]): string;
export var sep: string;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.