basarat / basarat/typescript-book
Confusion on modules section
- Dominant language
- TypeScript
- Stars
- 21.6k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
The section [where the global module declaration explained](https://basarat.gitbook.io/typescript/project/modules/external-modules#overturning-dynamic-lookup-just-for-types) there is an example like that:
```
// global.d.ts
declare module 'foo' {
// Some variable declarations
export var bar: number; /*sample*/
}
```
and
```
// anyOtherTsFileInYourProject.ts
import * as foo from 'foo';
// TypeScript assumes (without doing any lookup) that
// foo is {bar:number}
```
I can't achieve to make this work. I'm not quite sure this is a typo or something else or I don't understand the concept very well as a learner. But if I define the module like that, I can make it work:
```
declare module "foo" {
// Some variable declarations
export type bar = number; /*sample*/
}
```
Contributor guide
Research direction
Start with the linked modules documentation section and reproduce both declaration examples in a small TypeScript project. Check whether the `export var bar: number` example behaves as described; done means correcting the example or clarifying the explanation so the documented module declaration is accurate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100