2

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 :)

0

2 Answers 2

6

ok wow - it isnt a typescript, but an ts-node issue

in the example link the package.json script "dev" is setup like

"scripts": { 
  "dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", 
} 

but has to be:

"scripts": { 
  "dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' --files src/index.ts", 
} 

('--files' has to be added)

sorry for the confusion but hopefully it helps someone running in the same issue :)

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

1 Comment

Thanks, I searched everywhere for an answer but couldn't figure out why until I saw this
1

I was facing the same problem. My VS was able to detect *.d.ts file but in compiler I was getting error. The only fix which I needed was to add --files in the package.json script for running the local server. Thanks to @skizzle

Example -

"exec": "ts-node -r tsconfig-paths/register --files ./src/index.ts",

Comments

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.