TypeScript behavior

I'm doing some simple JavaScript coding exercises in TS and have come across this odd behavior I haven't encountered before. I have only the following code:
const inputs: Array<Array<any>> = [
[1, 2, 4, 0],
[1, 2, [4, 0]],
[[[2, 3, 4, 5]]],
];
const inputs: Array<Array<any>> = [
[1, 2, 4, 0],
[1, 2, [4, 0]],
[[[2, 3, 4, 5]]],
];
I get the following error:
Cannot redeclare block-scoped variable 'inputs'.ts(2451)
const inputs: any[][]
Cannot redeclare block-scoped variable 'inputs'.ts(2451)
const inputs: any[][]
Did a really quick Google search, and it seems to be because it's in the global scope. So I put it in a function and it works. Now, when I try this code only and by itself:
const x: String = "Hello";
const x: String = "Hello";
I get no such error. Why is that?
2 Replies
Joao
Joao14mo ago
Sometimes the TS server gets hung up, try to restart it
vince
vince14mo ago
It was a linter error, but I actually didn't try running it lol, let me check now It runs in ts-node lol Ohhh I see, it's because my vscode linter is somehow tied to my workspace (folder) rather than each file, so because I declared it in another file inside my workspace, it's throwing a warning. That's weird Thanks!
Want results from more Discord servers?
Add your server