1

So, I'm new to TypeScript and I wanted to convert a really small NodeJS project I was doing in plain JavaScript to TypeScript. In that project, I use some npm modules that have a definition under the @types scope, but others don't.

So, I figured I'd create these declarations for myself in my project, without having to change those third-party modules. However, no matter where I put the .d.ts file, TypeScript does not seem to recognize it.

src/typings.d.ts

import stream = require( 'stream' );
import http = require( 'http' );

declare module "flatten" {
    function flatten ( ...arrays : any[] ) : any[];

    export = flatten;
}

declare module "got" {
    //...
}

And then when I try to use the module flatten, for instance:

src/manager.ts

import flatten = require( 'flatten' );
//...

I get the error:

src/manager.ts(1,27): error TS2307: Cannot find module 'flatten'.

My tsconfig.json looks like this:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "noImplicitAny": true,
        "sourceMap": true,
        "outDir": "lib/" 
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}
3
  • Possible duplicate of Require custom module with npm and typescript Commented Oct 14, 2016 at 19:03
  • Doesn't seem like it. In this case, the external modules are not mine, so I can't just create a file in them. Commented Oct 14, 2016 at 19:35
  • Then maybe this: stackoverflow.com/q/29653735/215552. They are basically demonstrating the same error. You'll need to adapt them to your specific circumstances. There are a number of possible duplicates in the Related section; this is not an uncommon error. Commented Oct 14, 2016 at 19:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.