skip to Main Content

I’m having issues with ts error in my .js file when I don’t have any typescript environment installed, both locally & globally. I tried something like "javascript.validate.enable": false but I don’t want to use it, since it removes all error checks.

Here is my simple code:

//Part 1

function greeting() {
    return "Good Morning!";
}

let message = greeting;
message();
greeting();

//Part 2

function greeting() {
    return "Good Morning!";
}

function printMessage(anfunction) {
    console.log(anfunction());
}

printMessage(greeting);

//Part 3

function greeting() {
    return function () {
        return "Good Morning!";
    };
}

let anFunction = greeting();
let message = anFunction();

Here is .ts error:

Cannot redeclare block-scoped variable 'message'.ts(2451)
let message: {
    (): string;
    (): string;
    (): () => string;
}

I appreciate your help.

2

Answers


  1. Chosen as BEST ANSWER

    I realised it has nothing to do with TypeScript. I have ESLint plugin enabled, so it simply displays them as ts error...


  2. You use in Part3 let message = ..., so you redeclare a let-variable.
    You can set message like message = ...

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search