deno_lint icon indicating copy to clipboard operation
deno_lint copied to clipboard

Support for global declarations

Open Soremwar opened this issue 3 years ago • 0 comments

Note: This demonstration is a corner case and should be avoided by developers when possible. However since it's supported by TypeScript and in lack of a better solution it should be considered a "feature".

types.ts

declare global {
  var x: number;
}

globalThis.x = 1;

export {};

mod.ts

import "./types.ts";

console.log(x); ///Outputs 1, there is no compilation error

TypeScript is ok with this, and since you are writing a property in globalThis on import, JavaScript is as well. However deno lint will mark x as undefined.

Soremwar avatar Nov 13 '20 02:11 Soremwar