Skip to content

Code cleanup: isIntersectionType & similar internallyΒ #50005

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions