You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When pattern matching against multiple attributes in an object, ts-pattern will throw a runtime error that the exhaustive pattern matching was not able to spot at build-time if one of the attributes is misspelled.
import{match}from"ts-pattern";typePerson={sex: "Male"|"Female";age: "Adult"|"Child";};functionsummary(person: Person): string{return(match(person)// Typo – "agf" should be "age".with({sex: "Female",agf: "Adult"},()=>"Woman").with({sex: "Female",age: "Child"},()=>"Girl").with({sex: "Male",age: "Adult"},()=>"Man").with({sex: "Male",age: "Child"},()=>"Boy")// there is no TS error.exhaustive());}// yet this throws an error at runtime :(console.log(summary({sex: "Female",age: "Adult"}));
Versions
TypeScript version: 4.3.5
ts-pattern version: 3.2.4
environment: browser + version / node version / deno version
Thanks – this library is great!
The text was updated successfully, but these errors were encountered:
Describe the bug
When pattern matching against multiple attributes in an object,
ts-pattern
will throw a runtime error that the exhaustive pattern matching was not able to spot at build-time if one of the attributes is misspelled.Code Sandbox with a minimal reproduction case
https://codesandbox.io/s/elated-wilbur-h0mz2?file=/src/index.ts
(copy+pasted too):
Versions
Thanks – this library is great!
The text was updated successfully, but these errors were encountered: