basarat / basarat/typescript-book

Confusion on modules section

Open
#603 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.