Categories
Mastering Development

typescript .d.ts file not recognized by typescript but vsc

Update:

it isnt a typescript, but ts-node "issue"

i answered to myself so if ure still interested in the "issue" – read further 🙂

sorry for the confusion


maybe I have a TOTALLY wrong idea of the index.d.ts file.. but my idea was, that i can declare types within it and they are then "globally defined", so i dont have to redeclare them everywhere i use them (file a.ts and b.ts)

structure:

root
  src
    a.ts
    b.ts
  node_modules
  tsconfig.json
  index.d.ts
  package.json

for example i have a index.d.ts file:

type XYZType = { test: string }

in my ./src/a.ts I have:

const x: XYZType = { test: 'hello' }
console.log(x)

in my ./src/b.ts I have:

const x: XYZType = { test: 'world' }
console.log(x)

however vsc (Visual Studio Code) doesn’t complain about missing XYZType Type.. but when I try to let typescript compile, it does…:

error TS2304: Cannot find name 'XYZType'.

and points to file a.ts and b.ts

so.. to be obvious.. it looks like I do something wrong..

i followed the little example from levelup link

so my tsconfig.json looks like

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*", "src/types/*"]
    }
  },
  "include": ["src/**/*"]
}

i’m using:

    "ts-node": "^9.0.0",
    "typescript": "^4.0.3"

i found a lot of stack overflow requests with the same title.. but totally different content (own package declarations?) so this is why it confuses me and i have the feeling im totally wrong with the approach im looking for

hope anybody can help and explain whats wrong :/

thanks in advance 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *