add `structuredclone` support
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
structuredclone returnsany, and this is horrible as JSON.parse
I think there are two solution for this.
- return
unknowninstead ofany - return appropriate type which depends on the args
Thanks
If you would love to, I'd like to create a PR for this topic!!
@ryoppippi Could you do me a favour? Could you dig out in TS's issues the reason why structuredClone returns any and not T? Feels like an obvious candidate to be a generic function, I'd love to know why they didn't go that way.
Related: https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1237 @mattpocock @ryoppippi
They have a system that automatically generates types from new specs, but I guess it is not advanced enough to support generics (or maybe the spec is not written in a way that gets picked up as a generic function), so it ended up with anys instead. So no-one decided to use any, it was just automatically generated like that, and no-one fixed it yet.
In typescript 5.0, structuredclone is fully typed natively. Thank you for this discussion guys!!!
@ryoppippi Which version exactly is it typed fully? Both my package.json and VS Code workspace says I'm on version 5.0.2, but the definition of structuredClone in lib.dom.d.ts still uses any:
declare function structuredClone(value: any, options?: StructuredSerializeOptions): any;
@Svish
I created vanilla vite project and tested, and yeah you are right. structuerdClone still returns any.
However, in Sveltekit project, it works fine tho.
My environment is here
- Nvim 0.9
- Nvim-cmp
- TSServer 3.3.2
- Typescript 5.0
- Sveltekit 1.15.5
Here is the screenshot
idk why it works. But I think we need to open this issue again, maybe.
Thank you for letting me know this issue @Svish