Skip to content

feat: .narrow() method & typechecking perf improvement#261

Merged
gvergnaud merged 4 commits intomainfrom
gvergnaud/feat-narrow-method
Jul 26, 2025
Merged

feat: .narrow() method & typechecking perf improvement#261
gvergnaud merged 4 commits intomainfrom
gvergnaud/feat-narrow-method

Conversation

@gvergnaud
Copy link
Owner

@gvergnaud gvergnaud commented Jun 11, 2024

Add a .narrow() method to force a deep type narrowing after a .with clause. See https://x.com/GabrielVergnaud/status/1795208610965782626

Example:

const fn = (input: { prop?: string }) =>
      match(input)
        .with({ prop: P.nullish.optional() }, () => false)
        .narrow()
        .otherwise(({ prop }) => {
          //          ^? string
          return true;
        });

@gvergnaud gvergnaud force-pushed the gvergnaud/feat-narrow-method branch 2 times, most recently from dbbf6a0 to 273c223 Compare June 12, 2024 12:33
@gvergnaud gvergnaud changed the title Gvergnaud/feat narrow method feat: .narrow() method & typechecking perf improvement Jun 12, 2024
@gvergnaud gvergnaud force-pushed the gvergnaud/feat-narrow-method branch from 6833be9 to 1856ad3 Compare July 19, 2025 10:24
@gvergnaud gvergnaud marked this pull request as ready for review July 26, 2025 13:49
@gvergnaud gvergnaud merged commit 999128b into main Jul 26, 2025
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