Closed stof closed 2 years ago
@kevinpagtakhan any idea about when this could be fixed ? It is quite annoying that importing @amplitude/analytics-browser
breaks the type checking of unrelated code in our project.
Hey @stof! Thanks for choosing Amplitude. I opened a PR to remove the dependency on @types/node
in our internal types package. I'll have some folks take a look at it and we'll get it out as soon as we can.
Thanks
Expected Behavior
Importing
@amplitude/analytics-browser
should not force the loading of types defined in@types/node
Current Behavior
@amplitude/analytics-browser
imports@amplitude/analytics-types
, which references the node types:The beginning of
node_modules/@amplitude/analytics-types/lib/response.d.ts
looks like that:This reference to the node types is inserted by the compiler due to using
NodeJS.ErrnoException
in the type declaration ofSystemErrorResponse
. But this causes the loading of all of@types/node
, which will then define the return type ofsetTimeout
as being aTimeout
object and not a number, which is very annoying when writing a project targetting the web.Possible Solution
Types relying on Node types should be defined in
@amplitude/analytics-node
rather than@amplitude/analytics-types
. Or a different definition ofSystemErrorResponse
should be provided.Steps to Reproduce
yarn add --dev @amplitude/analytics-browser @types/node
Add this code in
test.ts
:Add this code in
tsconfig.json
:tsc -p .
)Type 'Timeout' is not assignable to type 'number'.
reported on thea
variable assignmentEnvironment
@amplitude/analytics-browser
1.2.0