Comments (10)
Looks great, @gvergnaud! Thanks again for all your time & effort.
from ts-pattern.
Thanks for the report, I fixed it in this commit, I'll followup with a patch release shortly!
from ts-pattern.
@gvergnaud amazing! Thanks for resolving.
from ts-pattern.
I cloned the repo, built it locally, and linked it with my test project. I see the runtime execution is working, but I'm still seeing handlers typed as a union of errors. Attached a quick screenshot of Intellisense in VSCode:
Note that Result.match
there is a wrapper, but I'm calling require("ts-pattern").match(err)
behind the Intellisense window.
I've definitely got the commit pulled:
And require.resolve
is reporting the link is working:
from ts-pattern.
Here is your own codesandbox example using the prerelease including the fix (3.3.4-rc.0
): https://codesandbox.io/s/mystifying-mcclintock-53fhk?file=/src/index.ts
It seems to fix your issue, but please try it again on your own codebase (make sure you aren't hitting Typescript's cache). If you still run in the same issue, could you provide another sandbox with a repro case?
from ts-pattern.
Huh - fair enough! The codesandbox definitely works as expected, I'll see if I can figure out why VSCode isn't showing me the right Intellisense. Thanks!
EDIT: https://codesandbox.io/s/hardcore-brook-egf5e may (or may not be) a worthy issue. If I add optional properties to the sub-class Errors, type inference does not work (as before). My initial problem was that the sub-classes had no extra properties, so type inference didn't introduce meaningful behavior. Here, I'd expect the match
return type to be string | undefined
and the code should compile.
from ts-pattern.
Oh I see, I think that's because a regular error is structurally assignable to your custom one since all of its properties are optional. I'll see what I can do
from ts-pattern.
Makes sense - my use case is maybe unusual. I'm working on implementing https://doc.rust-lang.org/std/result/enum.Result.html in TypeScript, and using match
to unwrap the ok/err states, and then using match
again to unwrap the error union. Using and matching on custom errors is meaningful, even if they are all assignable to each other. Anyways, I appreciate your time and effort here! This library is really amazing to use.
from ts-pattern.
Ok this time I think I fixed it for real ;) https://codesandbox.io/s/eloquent-feather-u1zvj?file=/src/index.ts you can try the latest RC and if that works for you I'll turn it in a patch version
from ts-pattern.
Released in v3.3.4
from ts-pattern.
Related Issues (20)
- Type '"error"' is not assignable to type 'KnownPattern<"ok"> HOT 6
- Support Awaited<T>
- Many JSDoc examples are incorrect HOT 1
- Object with `any` breaks `.with` chaining HOT 2
- How do I return a string | null from a match HOT 2
- Nullish pattern doesn't work with omitted fields HOT 2
- Seemingly incorrect tuple maching types HOT 1
- Support type predicate return type at `.when()` callback HOT 4
- Type NonExhaustiveError<BoardDto> has no call signatures
- Preventing use of `.exhaustive()` for enum checks HOT 1
- Handle readonly arrays in .exhaustive() HOT 2
- Support point-free style HOT 3
- Select sub-type for exhaustive check. E.g. `.exhaustive(([state, event]) => event.type)`
- Handling of undefined typings in tuples HOT 1
- a way to split long match blocks
- Predicate factory HOT 3
- .safeExhaustive HOT 1
- Deconstruct string matched with `.startsWith`, `.endsWith`, `regex` HOT 2
- How to check if a key of unknown type exists on an object? HOT 3
- Enter multiple pipeline for objects type match HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-pattern.