Uuid: @types/uuid references @types/node

Created on 23 Sep 2019  路  6Comments  路  Source: uuidjs/uuid

Unfortunately I'm trying to use this library with Typescript, so I need to use @types/uuid, but that contains a reference to Buffer in globals.d.ts which means it pulls in @types/node, which breaks my build. I'm writing code for browsers, not node.

There would be a few possible fixes for this, including just removing the reference to Buffer and just using Array / ArrayLike - or creating an interface for Buffer instead of pulling in the one from node...

Most helpful comment

Oh that would be excellent :)

So the problem for me is purely in the DefinitelyTyped @types/uuid definition from what I can tell. Inside that type it pulls in a reference to @types/node, because of Buffer - which is located in the node globals.d.ts.

But as I'm doing browser development (not making a node app) I can't use anything from here, and the presence of those types breaks things like setTimeout (makes its return type NodeJS.Timer instead of number).

This is a problem that has come up a few times before in other projects, and it's one of the pains of the ecosystem :( It normally just requires someone to sort of the types to remove that dependency.

Let me know if you need any more info, and thank you for the reply!

All 6 comments

@sam-s4s thanks for reporting this.

I am currently trying to make this library esmodule ready and in the process I also want to improve TypeScript support.

Could you provide me with a bit more detailed steps to reproduce or sample code/commands where things fall apart for you?

Oh that would be excellent :)

So the problem for me is purely in the DefinitelyTyped @types/uuid definition from what I can tell. Inside that type it pulls in a reference to @types/node, because of Buffer - which is located in the node globals.d.ts.

But as I'm doing browser development (not making a node app) I can't use anything from here, and the presence of those types breaks things like setTimeout (makes its return type NodeJS.Timer instead of number).

This is a problem that has come up a few times before in other projects, and it's one of the pains of the ecosystem :( It normally just requires someone to sort of the types to remove that dependency.

Let me know if you need any more info, and thank you for the reply!

If you have a create-react-app

put the following in yourreact-app-env.d.ts file

declare module 'uuid/v4' {
  export default function uuid() {}
}

A warning that this change has broken Typescript in our app! More info here: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/41814#issuecomment-580763714

Thank you for doing this - my problem is solved <3

@types/[email protected] has finally been released and should fix this issue. Feel free to create a new issue if you feel that this problem has not been solved yet.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

8bitjoey picture 8bitjoey  路  5Comments

Kmaschta picture Kmaschta  路  5Comments

BinitaBharati picture BinitaBharati  路  9Comments

nemoload picture nemoload  路  3Comments

ctavan picture ctavan  路  5Comments