Skip to content

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

Description

@AnupamKhosla

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions