admin管理员组文章数量:1024624
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.
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.
本文标签: typescriptDenots typing support identifies lists (string) as empty object ( )Stack Overflow
版权声明:本文标题:typescript - Deno-ts typing support identifies lists (string[], ...) as empty object ({ }) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745608591a2158873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论