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

[BUGFIX release] Fix unsafe internal cast for NativeArray #20227

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

chriskrycho
Copy link
Contributor

@chriskrycho chriskrycho commented Oct 18, 2022

  • For casting to NativeArray from T[] & EmberArray<unknown>: we do not have enough information to be able to tell TypeScript that the cast is safe here (and likely never will). TS 4.9 seems to handle the intersection type more robustly, though it is not yet documented. Here we make the cast from T[] & EmberArray<T> to NativeArray<T> even more explicitly unsafe via an as unknown intermediary cast.

  • For handling a proxy getter: TS' intersection of the this type for the get() method on a proxy receiver object used in CoreObject now flags up that the type of this may not be exactly CoreObject. Using typeof this in that intersection instead allows TS to see that the trap is safe.

@chriskrycho chriskrycho changed the title [BUGFIX beta] Fix unsafe internal cast for NativeArray [BUGFIX release] Fix unsafe internal cast for NativeArray Oct 18, 2022
@chriskrycho chriskrycho force-pushed the bugfix-ts-4.9 branch 2 times, most recently from 362b769 to 1306987 Compare October 18, 2022 18:02
- For casting to `NativeArray` from `T[] & EmberArray<unknown>`: we do
  not have enough information to be able to tell TypeScript that the
  cast is safe here (and likely never will). TS 4.9 seems to handle the
  intersection type more robustly, though it is not yet documented.
  Here we make the cast from `T[] & EmberArray<T>` to `NativeArray<T>`
  even *more* explicitly unsafe via an `as unknown` intermediary cast.

- For handling a proxy getter: TS' intersection of the `this` type for
  the `get()` method on a proxy receiver object used in `CoreObject`
  now flags up that the type of `this` may *not* be exactly
  `CoreObject`. Using `typeof this` in that intersection instead allows
  TS to see that the trap is safe.
@chriskrycho chriskrycho merged commit 17a8718 into master Oct 18, 2022
@chriskrycho chriskrycho deleted the bugfix-ts-4.9 branch October 18, 2022 20:02
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

Successfully merging this pull request may close these issues.

1 participant