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

Code cleanup: isIntersectionType & similar internally #50005

Closed
5 tasks done
JoshuaKGoldberg opened this issue Jul 22, 2022 · 1 comment
Closed
5 tasks done

Code cleanup: isIntersectionType & similar internally #50005

JoshuaKGoldberg opened this issue Jul 22, 2022 · 1 comment

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Jul 22, 2022

Suggestion

πŸ” Search Terms

isIntersectionType type predicate internal source code

βœ… Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Spinning #49727 (comment) into its own issue: there are a lot of type assertions internal to TypeScript that seem to predate type predicates.

It'd be nice to test out this this kind of change to the internal TypeScript source code:

- if (type.flags & TypeFlags.Intersection) {
+ if (isIntersectionType(type)) {
-     for (const subType of (type as IntersectionType).types) {
+     for (const subType of type.types) {

πŸ“ƒ Motivating Example

n/a

πŸ’» Use Cases

See changes in #49727.

Edit: ...and see #50010 for a draft PR.

@JoshuaKGoldberg
Copy link
Contributor Author

Per #50010 (comment), perf is hurt by this 😒.

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 a pull request may close this issue.

1 participant