Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add structuredclone support #82

Open
ryoppippi opened this issue Feb 25, 2023 · 7 comments
Open

add structuredclone support #82

ryoppippi opened this issue Feb 25, 2023 · 7 comments

Comments

@ryoppippi
Copy link

ryoppippi commented Feb 25, 2023

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 unknown instead of any
  • return appropriate type which depends on the args

Thanks

@ryoppippi
Copy link
Author

If you would love to, I'd like to create a PR for this topic!!

@mattpocock
Copy link
Owner

@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.

@Jacob-Lockwood
Copy link

Jacob-Lockwood commented Feb 26, 2023

@guillaumebrunerie
Copy link

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.

@ryoppippi
Copy link
Author

In typescript 5.0, structuredclone is fully typed natively. Thank you for this discussion guys!!!

@Svish
Copy link

Svish commented Apr 20, 2023

@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;

@ryoppippi
Copy link
Author

ryoppippi commented Apr 20, 2023

@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
    スクリーンショット 2023-04-20 18 01 10

idk why it works. But I think we need to open this issue again, maybe.

Thank you for letting me know this issue @Svish

@ryoppippi ryoppippi reopened this Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants