Skip to content

DOM suggestion: customisable history.state type #36178

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

Open
5 tasks
OliverJAsh opened this issue Jan 14, 2020 · 4 comments
Open
5 tasks

DOM suggestion: customisable history.state type #36178

OliverJAsh opened this issue Jan 14, 2020 · 4 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jan 14, 2020

Search Terms

dom lib window state history any unknown

Suggestion

Currently window.history.state has type any. Could we provide a way for users to customise this type? Perhaps by making it generic or allowing the type to be changed through declaration merging.

Failing that, could we replace the any type with unknown, so we have type safety and users are forced to validate/widen the type?

Another possible solution: if TypeScript provided a way to override any types (#4062, #26188).

Also related:

Use Cases

Examples

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@falsandtru
Copy link
Contributor

Since history.state can be changed from anywhere, its type is unreliable. We have to validate history.state value each access. The value should be typed then.

@falsandtru
Copy link
Contributor

Another code come from common libraries, other teams, or browser extensions may also use history.state.

https://github.com/defunkt/jquery-pjax/blob/master/jquery.pjax.js#L282-L293
https://github.com/falsandtru/pjax-api/blob/master/src/layer/data/store/state.ts

@OliverJAsh
Copy link
Contributor Author

In that case it sounds like unknown is the best bet

@nmain100
Copy link

If taking that approach, this becomes a duplicate of #26188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants