denoland / vscode_deno

Visual Studio Code plugin for Deno
https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno
MIT License
1.5k stars 146 forks source link

False positive deno-ts(2367)? #1151

Open lcrocker opened 3 months ago

lcrocker commented 3 months ago

This code runs fine with no errors, and passes deno lint. But vscode red-squigglies line 17 with a deno-ts(2367) error. Apparently the throw in the line above convinces the parser that the array length is exactly five, and ignores that a.clear() has changed it to zero.

class A {
    public a: number[] = [];

    constructor(s: number) {
        this.a = new Array(s).fill(0);
    }
    public clear() {
        this.a.splice(0, this.a.length);
    }
}

function run() {
    const x = new A(5);
    if (5 !== x.a.length) throw new Error("oops");
    x.clear();
    if (0 !== x.a.length) throw new Error("oops");
}

run();

I can see how trying to catch the side effects of every call might be too much to ask for the parser, but is there a way I can suppress the red squiggly?

Screenshot: ss20240816

vscode: 1.92.1 deno: 1.45.5 extension: 3.38.2