1

This is the same issue as How to allow modules that have missing .d.ts type definition?

VS Code stopped complaining after adding those files, but trying to compile using gulp sadly throw an error in the console.

(In fact today I noticed VS code stopped displaying most of the errors)

In ./src/dts/ I have:

dyo.d.ts

declare module 'dyo';

tsconfig.json

{
  "compilerOptions": {
    "lib": ["dom", "es2016", "es2017.object"],
    "rootDir": "src",
    "target": "es5",
    "outDir": "build",
    "moduleResolution": "node",
    //"noImplicitAny": false,
    "removeComments": true,
    "typeRoots": [
      "src/dts",
      "node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules"
  ],
  "files": [
    "./src/dts/dyo.d.ts",
    "./src/dts/randomseed.d.ts"
  ]
}

The error:

error TS7016: Could not find a declaration file for module 'dyo'. '/mediatest/node_modules/dyo/dist/dyo.umd.js' implicitly has an 'any' type. Try npm install @types/dyo if it exists or add a new declaration (.d.ts) file containing declare module 'dyo';

I include the modules like so:

import { h, render } from 'dyo'

import * as _rng from 'random-seed'

The second module isn't working either.

The previous answer suggested to include files property and another question somewhere said to include the typeRoots property but both settings doesn't seem to be working.

Sorry for spamming SO about my typescript questions.

1 Answer 1

2

I would suggest switching to types from typeRoots and using an include pattern rather than files.

{
  "compilerOptions": {
    "lib": ["dom", "es2016", "es2017.object"],
    "rootDir": "src",
    "target": "es5",
    "outDir": "build",
    "moduleResolution": "node",
    "removeComments": true,
    "types": [
      "node"
    ]
  },
  "include": [
    "**/*.ts"
  ]
}

I included the node type as well since you are using node module resolution, be sure to install @types/node if you have not already.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer, I've installed @types/node and change the configuration, but I still get Try npm install @types/dyo` if it exists or add a new declaration (.d.ts) file containing `declare module 'dyo';`` :/
I found the cause of it, gulp-typescript doesn't use tsconfig.json. I was able to change it's configuration to use the file. Finally. Thanks, it helped a lot.
You can bypass this in TypeScript configuration by using noImplicitAny: false, see here : stackoverflow.com/a/65687243/6380030

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.