I work on VS Code and I use Deno. The deno.json
in my project is quite simple:
{
"compilerOptions": {
"lib": [
"DOM"
]
},
"imports": {
"@std/path": "jsr:@std/path@^1.0.8"
}
}
Same for the tsconfig.json
:
{
"compilerOptions": {
"target": "ES2023",
"module": "ES2022",
"moduleResolution": "bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
I'm dealing a deno-ts
problem. To be more specific, the type checking of arrays doesn't seem to work at all.
I was working on a simple function whose purpose is to loop through a list of HTML pictures to link the <img>
sources to the actual jpg/png. To make sure the query is correct, I check if the length of the list of elements is equal to the one of pictures:
function setPictures(authors: Author[]) {
const imgList = document.querySelectorAll(".main__author__picture img")
if (imgList.length !== authors.length) {
console.error("lengths don't match !")
return
}
}
Here's the error due to authors.length
:
Property 'length' does not exist on type '{}'.deno-ts(2339)
This is due to the fact that deno-ts doesn't understand what lists are:
(parameter) authors: {}
At first, I thought maybe this is due to the custom type Author
. So I tried to write a simple array and let deno infer the type:
let test = ["yes", "no"]
However, the problem persists:
let test: {}
Enforcing the type does not fix it :
let test: string[]
I think it has to do with my configuration of Deno. Anyway, the code compiles because there is no syntax error here. It is an intellisense error.
The settings.json
of my project (inside .vscode
) is also very simple:
{
"deno.enable": true,
"deno.lint": true
}
I work on VS Code and I use Deno. The deno.json
in my project is quite simple:
{
"compilerOptions": {
"lib": [
"DOM"
]
},
"imports": {
"@std/path": "jsr:@std/path@^1.0.8"
}
}
Same for the tsconfig.json
:
{
"compilerOptions": {
"target": "ES2023",
"module": "ES2022",
"moduleResolution": "bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
I'm dealing a deno-ts
problem. To be more specific, the type checking of arrays doesn't seem to work at all.
I was working on a simple function whose purpose is to loop through a list of HTML pictures to link the <img>
sources to the actual jpg/png. To make sure the query is correct, I check if the length of the list of elements is equal to the one of pictures:
function setPictures(authors: Author[]) {
const imgList = document.querySelectorAll(".main__author__picture img")
if (imgList.length !== authors.length) {
console.error("lengths don't match !")
return
}
}
Here's the error due to authors.length
:
Property 'length' does not exist on type '{}'.deno-ts(2339)
This is due to the fact that deno-ts doesn't understand what lists are:
(parameter) authors: {}
At first, I thought maybe this is due to the custom type Author
. So I tried to write a simple array and let deno infer the type:
let test = ["yes", "no"]
However, the problem persists:
let test: {}
Enforcing the type does not fix it :
let test: string[]
I think it has to do with my configuration of Deno. Anyway, the code compiles because there is no syntax error here. It is an intellisense error.
The settings.json
of my project (inside .vscode
) is also very simple:
{
"deno.enable": true,
"deno.lint": true
}
Share
Improve this question
edited Nov 20, 2024 at 6:29
Eli
618 bronze badges
asked Nov 18, 2024 at 16:12
PehnnyPehnny
1291 silver badge6 bronze badges
2 Answers
Reset to default 0You can install these Node types deno add npm:@types/node
I found a solution in the official deno documentation. The project needs node types to type check lists like string[]
correctly.
I faced the same issue with types like Array<T>
. However, declaring :
/// <reference types="npm:@types/node" />
At the head of the .mts
file fixed everything.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745608592a4635818.html
评论列表(0条)