basarat / basarat/typescript-book

Ambient declarations on Declaration files page has erroneous code example https://basarat.gitbook.io/typescript/type-system/intro/d.ts

Open
#705 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

Tutorial Documentation: https://basarat.gitbook.io/typescript/type-system/intro/d.ts

> You can tell TypeScript that you are trying to describe code that exists elsewhere (e.g. written in JavaScript/CoffeeScript/The runtime environment like the browser or Node.js) using the declare keyword. As a quick example:

> foo = 123; // Error: `foo` is not defined
vs.

> declare var foo: any;
foo = 123; // allowed

Here `foo = 123;` is not allowed in javascript at all, because of the reference error. In Typescript, you can't have `foo = 123` in the declaration file `.d.ts`; it is supposed to have only type declarations.

`foo = 123;` in a `.ts` file along with `declare var foo: any;` in the `.d.ts` file will cause Typescript to skip the reference error.

Contributor guide

Open the contributing guide

Research direction

Open the tutorial documentation at https://basarat.gitbook.io/typescript/type-system/intro/d.ts and review the ambient declaration example against the issue’s explanation of .d.ts files. Correct the erroneous code example so it distinguishes declaration-file syntax from executable TypeScript, then verify the rendered page and its surrounding wording.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.