-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forbid excess properties when matching tags (#1681)
- Loading branch information
1 parent
83c3de7
commit e5cd27c
Showing
9 changed files
with
272 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"effect": patch | ||
--- | ||
|
||
forbid excess properties when matching tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { pipe } from "effect/Function" | ||
import * as M from "effect/Match" | ||
|
||
type Value = { _tag: "A"; a: number } | { _tag: "B"; b: number } | ||
const value = { _tag: "A", a: 123 } as Value | ||
|
||
// ------------------------------------------------------------------------------------- | ||
// valueTags | ||
// ------------------------------------------------------------------------------------- | ||
|
||
// $ExpectType string | number | ||
pipe( | ||
value, | ||
M.valueTags({ | ||
A: (_) => _.a, | ||
B: () => "B" | ||
}) | ||
) | ||
|
||
pipe( | ||
value, | ||
M.valueTags({ | ||
A: (_) => _.a, | ||
B: () => "B", | ||
// @ts-expect-error | ||
C: () => false | ||
}) | ||
) | ||
|
||
// ------------------------------------------------------------------------------------- | ||
// typeTags | ||
// ------------------------------------------------------------------------------------- | ||
|
||
// $ExpectType string | number | ||
M.typeTags<Value>()({ | ||
A: (_) => _.a, | ||
B: () => "B" | ||
})(value) | ||
|
||
M.typeTags<Value>()({ | ||
A: (_) => _.a, | ||
B: () => "B", | ||
// @ts-expect-error | ||
C: () => false | ||
})(value) | ||
|
||
// ------------------------------------------------------------------------------------- | ||
// discriminators | ||
// ------------------------------------------------------------------------------------- | ||
|
||
// $ExpectType string | number | ||
pipe( | ||
M.type<Value>(), | ||
M.discriminators("_tag")({ | ||
A: (_) => _.a, | ||
B: () => "B" | ||
}), | ||
M.exhaustive | ||
)(value) | ||
|
||
pipe( | ||
M.type<Value>(), | ||
M.discriminators("_tag")({ | ||
A: (_) => _.a, | ||
B: () => "B", | ||
// @ts-expect-error | ||
C: () => false | ||
}), | ||
M.exhaustive | ||
)(value) | ||
|
||
// ------------------------------------------------------------------------------------- | ||
// discriminatorsExhaustive | ||
// ------------------------------------------------------------------------------------- | ||
|
||
// $ExpectType string | number | ||
pipe( | ||
M.type<Value>(), | ||
M.discriminatorsExhaustive("_tag")({ | ||
A: (_) => _.a, | ||
B: () => "B" | ||
}) | ||
)(value) | ||
|
||
pipe( | ||
M.type<Value>(), | ||
M.discriminatorsExhaustive("_tag")({ | ||
A: (_) => _.a, | ||
B: () => "B", | ||
// @ts-expect-error | ||
C: () => false | ||
}) | ||
)(value) | ||
|
||
// ------------------------------------------------------------------------------------- | ||
// tags | ||
// ------------------------------------------------------------------------------------- | ||
|
||
// $ExpectType string | number | ||
pipe( | ||
M.type<Value>(), | ||
M.tags({ | ||
A: (_) => _.a, | ||
B: () => "B" | ||
}), | ||
M.exhaustive | ||
)(value) | ||
|
||
pipe( | ||
M.type<Value>(), | ||
M.tags({ | ||
A: (_) => _.a, | ||
B: () => "B", | ||
// @ts-expect-error | ||
C: () => false | ||
}), | ||
M.exhaustive | ||
)(value) | ||
|
||
// ------------------------------------------------------------------------------------- | ||
// tagsExhaustive | ||
// ------------------------------------------------------------------------------------- | ||
|
||
// $ExpectType string | number | ||
pipe( | ||
M.type<Value>(), | ||
M.tagsExhaustive({ | ||
A: (_) => _.a, | ||
B: () => "B" | ||
}) | ||
)(value) | ||
|
||
pipe( | ||
M.type<Value>(), | ||
M.tagsExhaustive({ | ||
A: (_) => _.a, | ||
B: () => "B", | ||
// @ts-expect-error | ||
C: () => false | ||
}) | ||
)(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.