-
Notifications
You must be signed in to change notification settings - Fork 633
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
feat(assert): type narrowing for assertLess, assertLessOrEqual, asserGreater, assertGreaterOrEqual #6245
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6245 +/- ##
=======================================
Coverage 96.49% 96.49%
=======================================
Files 536 536
Lines 41179 41189 +10
Branches 6175 6178 +3
=======================================
+ Hits 39735 39745 +10
- Misses 1401 1402 +1
+ Partials 43 42 -1 ☔ View full report in Codecov by Sentry. |
dd18100
to
79e9937
Compare
On a second thought (after my #6244 issue), If x can be undefined, any comparison with const x = Math.random() > 1.0 ? 10 : undefined;
console.log(x < 3); // error: TS18048 [ERROR]: 'x' is possibly 'undefined'. So I've added typing for these assertions to also expect actual: Exclude<T, undefined> | null, The error isn't pretty, but it's better than nothing:
The
|
@@ -1,7 +1,7 @@ | |||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | |||
// This module is browser compatible. | |||
import { equal } from "./equal.ts"; | |||
import { format } from "@std/internal/format"; | |||
import { format } from "../internal/format.ts"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relative import doesn't work when published to JSR as each package is published independently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made that change because the @std
import led to this error when using the repo with file:///
imports from 3rd party code:
Relative import path "@std/internal/build-message" not prefixed with / or ./ or ../ and not in import map
Is there a syntax that would work in both cases, or should I revert the change from the first commit of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess an import map in the 3rd party code would solve the problem. Feel free to cherry-pick / ignore the first commit.
79e9937
to
78e5937
Compare
Fixes error `Relative import path "@std/internal/build-message" not prefixed with / or ./ or ../ and not in import map` when using the repo with file:/// import from 3rd party code
…rtGreaterOrEqual - disallow undefined actual values because any comparison with undefined returns false - disallow null expected values - narrow the returned type to exclude undefined
78e5937
to
80d9af5
Compare
This is a breaking change in the current format (The users will see the type error if the input type include Also I don't see much value to this narrowing of types as the same effect can be achieved by calling |
We first need to discuss what can/should be done about this in #6244 Closing for now |
undefined
returns falseFixes #6244.