jakey___
TTCTheo's Typesafe Cult
•Created by jakey___ on 6/7/2023 in #questions
Type declaration for js files
I have a boiled down hobby project that I would like to avoid having to add a compile step to (it's all server-side node.js). My thought was to use a tsconfig.json to allow my IDE to report the type errors for me and to establish the types themselves in separate .d.ts files.
My tsconfig.json looks like this :
{
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"checkJs": true,
"lib": ["es2022"],
"module": "es2022",
"target": "es2022",
"types": ["node"],
"moduleResolution": "node",
},
"include": [
"./**/.js",
"./*/.d.ts",
],
"exclude": [
"node_modules"
]
}
And just to stay with a simple example I have (These two are in the same directory)
Zone.js
class Zone {
constructor (name) {}
}
Zone.d.ts
declare class Zone {
constructor (name :string)
}
I'm using VSCode, and the report I'm getting from hovering over the
name
argument in the Zone constructor is any
, when I'd expect it to be string
.
Maybe the answer is obvious and I'm just up too late to see it with my tired brain, but any feedback here is appreciated. Thank you3 replies