ts-node ignores d.ts files while tsc successfully compiles the project

I was having a similar problem, but I could not add –files, because I run ts-node by registering the module through mocha (i.e. mocha -r ts-node/register …). I could solve it by adding a files and a ts-node section to tsconfig.json like this: // tsconfig.json { “ts-node”: { “files”: true }, “files”: [ “src/index.ts”, “src/global.d.ts” … Read more

NPM package cannot be used as a JSX Component – Type errors

Had the same issue. Just add this “resolutions”: { “@types/react”: “17.0.2”, “@types/react-dom”: “17.0.2” }, to package.json file and run yarn command. UPD: Just a bit detailed answer: @types/react-dom has its own dependencies and one of them is @types/react with a version set to ‘*’ – a major release, that now, probably, refers to 18. Even … Read more

Typescript 2.0. “types” field in tsconfig.json

As of TypeScript 2.* the ‘tsconfig.json’ has the following two properties available: { ‘typeRoots’: [], ‘types’: [] } I’ll detail both in order. ‘typeRoots’ specifies root folders in which the transpiler should look for type definitions (eg: ‘node_modules’). If you’ve been using typescript, you know that for different libraries that have not been written using … Read more

Exclude/overwrite npm-provided typings

Create node_modules folder under your src, then put typings of module(s) you want to overwrite inside: ├── node_modules │ └── … │ └── src ├── index.ts ├── … your codes … │ └── node_modules └── <module-to-be-overwritten> └── index.d.ts No need to modify compilerOptions in tsconfig.json. Read How TypeScript resolves modules section in https://www.typescriptlang.org/docs/handbook/module-resolution.html.

How to configure custom global interfaces (.d.ts files) for TypeScript?

“Magically available interfaces” or global types is highly discouraged and should mostly be left to legacy. Also, you should not be using ambient declaration files (e.g. d.ts files) for code that you are writing. These are meant to stand-in the place of external non-typescript code (essentially filling in the typescript types into js code so … Read more