0

In Visual Studio, as well as with the tsc on Ubuntu, I routinely encounter variables in TypeScript with the message Cannot find name 'variableName', where variableName is the variable which acts like a namespace. Hence, it can be crossfilter, or d3 for example.

What does this fundamentally mean?

I suppose this means that the typing definition isn't included in the tsconfig.json file?

When I try including the relevant typings directory file

typings
├── globals
│   └── crossfilter
│       ├── index.d.ts
│       └── typings.json
├── index.d.ts
└── modules
    └── d3
        ├── index.d.ts
        └── typings.json

by

{
  "compilerOptions": {
    "target": "es5",
    "sourceMap": false,
    "outDir": "./built",
    "rootDir": "src"
  },
  "include": [
    "**/*",
    "../../../typings"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": true
}

I still get the same Cannot find name variableName error.

Edit.

I don't understand the concept of the @types feature.

Another related concept I don't understand, what is the goal of the following command,

npm install --save @types/lodash

in relation to just including the .d.ts file in a typings/ directory like the above?

easytarget
  • 945
  • 2
  • 13
  • 35
  • You should `import` files that you use. – SLaks Jan 26 '18 at 16:48
  • I'd recommend against using the Typings CLI if possible - it's been deprecated in favor of [installing type definitions through NPM](https://stackoverflow.com/questions/38444279/how-should-i-use-types-with-typescript-2). – Joe Clay Jan 26 '18 at 16:52
  • @SLaks Currently this happens via the TypeScript `/// ` directive at the top of a file, where dependencies.ts contains more of these directives. – easytarget Jan 26 '18 at 16:52

0 Answers0