opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

Don't use lib dom during compilation

Open Flarna opened this issue 4 years ago • 4 comments
trafficstars

Currently tsconfig.json doesn't include a lib config. This results in automatically including dom - browser types (see https://www.typescriptlang.org/tsconfig#lib)

The only place where this is needed is for global this here

Should we aim to remove this to avoid that we use/rely on these types on other places?

Flarna avatar Feb 24 '21 19:02 Flarna

Is there a way to only include the lib in a single file or folder? We could always manually declare types ourselves if needed.

dyladan avatar Apr 09 '21 03:04 dyladan

I tried via /// <reference lib="dom" /> but it looks like it's available everywhere then. It even ends up in globalThis.js and globalThis.d.ts so it is even visible in consumers.

Maybe some background why I reported this. I found that removing lib dom results in following compile error in consoleLogger.ts:

This expression is not callable.
  Each member of the union type '{ <T, R>(this: (this: T) => R, thisArg: T): R; <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R; } | { <T>(this: new () => T, thisArg: T): void; <T, A extends any[]>(this: new (...args: A) => T, thisArg: T, args: A): void; }' has signatures, but none of those signatures are compatible with each other.

Reason is the Console is augmented in lib dom with by far more relaxed definitions.

Flarna avatar Apr 09 '21 07:04 Flarna

Only movement I've seen in this space is https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1207, which doesn't have much movement

SimenB avatar May 15 '23 07:05 SimenB