typescript-book icon indicating copy to clipboard operation
typescript-book copied to clipboard

Confusion on modules section

Open devserkan opened this issue 5 years ago • 0 comments

The section where the global module declaration explained 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*/
}

devserkan avatar Sep 02 '20 22:09 devserkan