microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.75k stars 12.46k forks source link

Visual Studio Code recognizes custom definition typing but not the TypeScript Compiler #6882

Closed kdcllc closed 8 years ago

kdcllc commented 8 years ago

I discovered the problem that TypeScript compiler recognizes the custom typing within the Visual Studio Code but when you attempt to compile it is not able to find the module.

I have custom typing in the following location:

tools/typings/yards.ts 

Here is my tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": true,
        "noResolve": false
    },

    "exclude": [
        "node_modules"
    ],
    "compileOnSave": false
}

I was able to solve the issue by adding custom.d.ts file in the same directory and add reference to my file definition then compiler recognized the type definition. Here is the link to the project that works: https://github.com/kdcllc/Angular-TypeScript-Starter/tree/typescript-workflow-with-gulp

mhegazy commented 8 years ago

can you run the compiler with --listFiles, and let us know what file is missed. we will need some more information to be able to diagnose the issue.

kdcllc commented 8 years ago

@mhegazy I ran the following c:\Dev_angular\Angular-TypeScript-Starter>tsc gulpfile.ts --listFiles --module commonjs gulpfile.ts(1,23): error TS2307: Cannot find module 'gulp'. tools/utils/application.ts(1,20): error TS2307: Cannot find module 'yargs'. C:/Users/Admin/AppData/Roaming/npm/node_modules/typescript/lib/lib.d.ts tools/utils/application.ts tools/config.ts gulpfile.ts

Command line does not produces the same results at all. When I use ts-node the gulp command runs with the fixes that I implemented. Thanks, kdcllc

kdcllc commented 8 years ago

@mhegazy Please close this issue. As I have stated in the original message the compiler read thru .d.ts files in order to load definition files. There at two ways to handle the loading of the types:

  1. all of the definition files to have d.ts extension or
  2. have a reference file with d.ts extension as i resorted to accomplish originally.

Thanks