Open OliverJAsh opened 4 years ago
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.
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
In that case it sounds like unknown
is the best bet
If taking that approach, this becomes a duplicate of https://github.com/microsoft/TypeScript/issues/26188
Search Terms
dom lib window state history any unknown
Suggestion
Currently
window.history.state
has typeany
. 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 withunknown
, 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 (https://github.com/microsoft/TypeScript/issues/4062, https://github.com/microsoft/TypeScript/issues/26188).Also related:
Use Cases
Examples
Checklist
My suggestion meets these guidelines: