Skip to content

Make assert method an assertion function in TS#840

Open
Andarist wants to merge 1 commit into
benjamn:masterfrom
Andarist:patch-1
Open

Make assert method an assertion function in TS#840
Andarist wants to merge 1 commit into
benjamn:masterfrom
Andarist:patch-1

Conversation

@Andarist

Copy link
Copy Markdown

This is available since TS 3.7:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions

It could be considered a breaking change. Note that DefinitelyTyped supports officially only the last 2 years of TS releases and that makes 4.1 the last supported version there: https://github.com/DefinitelyTyped/DefinitelyTyped#support-window

@davbrito

davbrito commented Nov 5, 2024

Copy link
Copy Markdown

I think this would be a great addition to the project. Any particular reason why it's not been merged yet?

As for the breaking change, what about adding an extra method called assertType? That way, people who are currently expecting the true return can still use assert without any problem.

@acidoxee

acidoxee commented Dec 3, 2024

Copy link
Copy Markdown

I'd like to second this, the .check/.assert distinction is already native to the lib, it's just missing the proper typings. It's a bummer having either to nest the code in if statements (to benefit from the current, limited type narrowing) or having to resort to unsound casts 🙏

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.

3 participants