ts-data-forge 14.6.4 → 14.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/expect-type.d.mts +2 -70
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +1 -68
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/index.d.mts +11 -6
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +10 -6
- package/dist/functional/index.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +2 -51
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +1 -41
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts +2 -34
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +1 -34
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +2 -89
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -88
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +2 -42
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +1 -40
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/number/num.d.mts +9 -1
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -16
- package/dist/number/num.mjs.map +1 -1
- package/dist/others/index.d.mts +1 -0
- package/dist/others/index.d.mts.map +1 -1
- package/dist/others/index.mjs +1 -0
- package/dist/others/index.mjs.map +1 -1
- package/dist/others/panic-error.d.mts +9 -0
- package/dist/others/panic-error.d.mts.map +1 -0
- package/dist/others/panic-error.mjs +9 -0
- package/dist/others/panic-error.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +2 -37
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +1 -92
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/types.d.mts +1 -41
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +5 -5
- package/src/expect-type.mts +2 -78
- package/src/functional/index.mts +31 -6
- package/src/guard/has-key.mts +2 -72
- package/src/guard/is-non-null-object.mts +2 -36
- package/src/guard/is-record.mts +2 -95
- package/src/guard/key-is-in.mts +2 -49
- package/src/number/num.mts +36 -28
- package/src/others/index.mts +1 -0
- package/src/others/panic-error.mts +8 -0
- package/src/others/unknown-to-string.mts +2 -111
- package/src/types.mts +4 -54
- package/dist/functional/async-result/async-result.d.mts +0 -16
- package/dist/functional/async-result/async-result.d.mts.map +0 -1
- package/dist/functional/async-result/async-result.mjs +0 -2
- package/dist/functional/async-result/async-result.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts +0 -39
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.mjs +0 -23
- package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts +0 -47
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.mjs +0 -10
- package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts +0 -53
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs +0 -15
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.d.mts +0 -35
- package/dist/functional/async-result/impl/async-result-map-err.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map-err.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.d.mts +0 -45
- package/dist/functional/async-result/impl/async-result-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts +0 -34
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +0 -37
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +0 -1
- package/dist/functional/async-result/impl/index.d.mts +0 -8
- package/dist/functional/async-result/impl/index.d.mts.map +0 -1
- package/dist/functional/async-result/impl/index.mjs +0 -8
- package/dist/functional/async-result/impl/index.mjs.map +0 -1
- package/dist/functional/async-result/impl/types.d.mts +0 -45
- package/dist/functional/async-result/impl/types.d.mts.map +0 -1
- package/dist/functional/async-result/impl/types.mjs +0 -2
- package/dist/functional/async-result/impl/types.mjs.map +0 -1
- package/dist/functional/async-result/index.d.mts +0 -2
- package/dist/functional/async-result/index.d.mts.map +0 -1
- package/dist/functional/async-result/index.mjs +0 -2
- package/dist/functional/async-result/index.mjs.map +0 -1
- package/dist/functional/match.d.mts +0 -80
- package/dist/functional/match.d.mts.map +0 -1
- package/dist/functional/match.mjs +0 -31
- package/dist/functional/match.mjs.map +0 -1
- package/dist/functional/optional/impl/index.d.mts +0 -19
- package/dist/functional/optional/impl/index.d.mts.map +0 -1
- package/dist/functional/optional/impl/index.mjs +0 -19
- package/dist/functional/optional/impl/index.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +0 -37
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +0 -22
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +0 -33
- package/dist/functional/optional/impl/optional-filter.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-filter.mjs +0 -25
- package/dist/functional/optional/impl/optional-filter.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +0 -39
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +0 -18
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +0 -27
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +0 -28
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +0 -23
- package/dist/functional/optional/impl/optional-is-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +0 -22
- package/dist/functional/optional/impl/optional-is-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +0 -21
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +0 -26
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +0 -24
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +0 -23
- package/dist/functional/optional/impl/optional-is-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-map.d.mts +0 -34
- package/dist/functional/optional/impl/optional-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-map.mjs +0 -22
- package/dist/functional/optional/impl/optional-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-match.d.mts +0 -48
- package/dist/functional/optional/impl/optional-match.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-match.mjs +0 -20
- package/dist/functional/optional/impl/optional-match.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-none.d.mts +0 -19
- package/dist/functional/optional/impl/optional-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-none.mjs +0 -19
- package/dist/functional/optional/impl/optional-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +0 -43
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +0 -16
- package/dist/functional/optional/impl/optional-or-else.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-some.d.mts +0 -22
- package/dist/functional/optional/impl/optional-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-some.mjs +0 -25
- package/dist/functional/optional/impl/optional-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +0 -37
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +0 -16
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +0 -31
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +0 -36
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +0 -32
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +0 -8
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +0 -35
- package/dist/functional/optional/impl/optional-zip.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-zip.mjs +0 -39
- package/dist/functional/optional/impl/optional-zip.mjs.map +0 -1
- package/dist/functional/optional/impl/tag.d.mts +0 -6
- package/dist/functional/optional/impl/tag.d.mts.map +0 -1
- package/dist/functional/optional/impl/tag.mjs +0 -4
- package/dist/functional/optional/impl/tag.mjs.map +0 -1
- package/dist/functional/optional/impl/types.d.mts +0 -24
- package/dist/functional/optional/impl/types.d.mts.map +0 -1
- package/dist/functional/optional/impl/types.mjs +0 -2
- package/dist/functional/optional/impl/types.mjs.map +0 -1
- package/dist/functional/optional/index.d.mts +0 -2
- package/dist/functional/optional/index.d.mts.map +0 -1
- package/dist/functional/optional/index.mjs +0 -2
- package/dist/functional/optional/index.mjs.map +0 -1
- package/dist/functional/optional/optional.d.mts +0 -16
- package/dist/functional/optional/optional.d.mts.map +0 -1
- package/dist/functional/optional/optional.mjs +0 -2
- package/dist/functional/optional/optional.mjs.map +0 -1
- package/dist/functional/pipe.d.mts +0 -102
- package/dist/functional/pipe.d.mts.map +0 -1
- package/dist/functional/pipe.mjs +0 -45
- package/dist/functional/pipe.mjs.map +0 -1
- package/dist/functional/result/impl/index.d.mts +0 -28
- package/dist/functional/result/impl/index.d.mts.map +0 -1
- package/dist/functional/result/impl/index.mjs +0 -28
- package/dist/functional/result/impl/index.mjs.map +0 -1
- package/dist/functional/result/impl/result-err.d.mts +0 -28
- package/dist/functional/result/impl/result-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-err.mjs +0 -31
- package/dist/functional/result/impl/result-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +0 -33
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +0 -23
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +0 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +0 -45
- package/dist/functional/result/impl/result-flat-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-flat-map.mjs +0 -21
- package/dist/functional/result/impl/result-flat-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-fold.d.mts +0 -50
- package/dist/functional/result/impl/result-fold.d.mts.map +0 -1
- package/dist/functional/result/impl/result-fold.mjs +0 -23
- package/dist/functional/result/impl/result-fold.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-optional.d.mts +0 -41
- package/dist/functional/result/impl/result-from-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-optional.mjs +0 -21
- package/dist/functional/result/impl/result-from-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +0 -43
- package/dist/functional/result/impl/result-from-promise.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-promise.mjs +0 -39
- package/dist/functional/result/impl/result-from-promise.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +0 -32
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +0 -46
- package/dist/functional/result/impl/result-from-throwable.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-err.d.mts +0 -23
- package/dist/functional/result/impl/result-is-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-err.mjs +0 -22
- package/dist/functional/result/impl/result-is-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +0 -23
- package/dist/functional/result/impl/result-is-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-ok.mjs +0 -22
- package/dist/functional/result/impl/result-is-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-result.d.mts +0 -22
- package/dist/functional/result/impl/result-is-result.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-result.mjs +0 -26
- package/dist/functional/result/impl/result-is-result.mjs.map +0 -1
- package/dist/functional/result/impl/result-map-err.d.mts +0 -39
- package/dist/functional/result/impl/result-map-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map-err.mjs +0 -22
- package/dist/functional/result/impl/result-map-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-map.d.mts +0 -39
- package/dist/functional/result/impl/result-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map.mjs +0 -22
- package/dist/functional/result/impl/result-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-match.d.mts +0 -47
- package/dist/functional/result/impl/result-match.d.mts.map +0 -1
- package/dist/functional/result/impl/result-match.mjs +0 -20
- package/dist/functional/result/impl/result-match.mjs.map +0 -1
- package/dist/functional/result/impl/result-ok.d.mts +0 -28
- package/dist/functional/result/impl/result-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-ok.mjs +0 -31
- package/dist/functional/result/impl/result-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-or-else.d.mts +0 -40
- package/dist/functional/result/impl/result-or-else.d.mts.map +0 -1
- package/dist/functional/result/impl/result-or-else.mjs +0 -17
- package/dist/functional/result/impl/result-or-else.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-try.d.mts +0 -51
- package/dist/functional/result/impl/result-safe-try.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-try.mjs +0 -35
- package/dist/functional/result/impl/result-safe-try.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.d.mts +0 -36
- package/dist/functional/result/impl/result-safe-unwrap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.mjs +0 -42
- package/dist/functional/result/impl/result-safe-unwrap.mjs.map +0 -1
- package/dist/functional/result/impl/result-swap.d.mts +0 -23
- package/dist/functional/result/impl/result-swap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-swap.mjs +0 -27
- package/dist/functional/result/impl/result-swap.mjs.map +0 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +0 -32
- package/dist/functional/result/impl/result-to-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-to-optional.mjs +0 -32
- package/dist/functional/result/impl/result-to-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +0 -46
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +0 -34
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +0 -26
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +0 -8
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +0 -40
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-zip.d.mts +0 -32
- package/dist/functional/result/impl/result-zip.d.mts.map +0 -1
- package/dist/functional/result/impl/result-zip.mjs +0 -37
- package/dist/functional/result/impl/result-zip.mjs.map +0 -1
- package/dist/functional/result/impl/tag.d.mts +0 -6
- package/dist/functional/result/impl/tag.d.mts.map +0 -1
- package/dist/functional/result/impl/tag.mjs +0 -4
- package/dist/functional/result/impl/tag.mjs.map +0 -1
- package/dist/functional/result/impl/types.d.mts +0 -31
- package/dist/functional/result/impl/types.d.mts.map +0 -1
- package/dist/functional/result/impl/types.mjs +0 -2
- package/dist/functional/result/impl/types.mjs.map +0 -1
- package/dist/functional/result/index.d.mts +0 -2
- package/dist/functional/result/index.d.mts.map +0 -1
- package/dist/functional/result/index.mjs +0 -2
- package/dist/functional/result/index.mjs.map +0 -1
- package/dist/functional/result/result.d.mts +0 -16
- package/dist/functional/result/result.d.mts.map +0 -1
- package/dist/functional/result/result.mjs +0 -2
- package/dist/functional/result/result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/index.d.mts +0 -29
- package/dist/functional/ternary-result/impl/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/index.mjs +0 -29
- package/dist/functional/ternary-result/impl/index.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/tag.d.mts +0 -8
- package/dist/functional/ternary-result/impl/tag.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/tag.mjs +0 -6
- package/dist/functional/ternary-result/impl/tag.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +0 -24
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +0 -39
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +0 -38
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +0 -27
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +0 -36
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +0 -32
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +0 -17
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +0 -29
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +0 -25
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +0 -10
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +0 -35
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +0 -52
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/types.d.mts +0 -26
- package/dist/functional/ternary-result/impl/types.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/types.mjs +0 -2
- package/dist/functional/ternary-result/impl/types.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts +0 -4
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +0 -13
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +0 -1
- package/dist/functional/ternary-result/index.d.mts +0 -2
- package/dist/functional/ternary-result/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/index.mjs +0 -2
- package/dist/functional/ternary-result/index.mjs.map +0 -1
- package/dist/functional/ternary-result/ternary-result.d.mts +0 -40
- package/dist/functional/ternary-result/ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/ternary-result.mjs +0 -2
- package/dist/functional/ternary-result/ternary-result.mjs.map +0 -1
- package/src/functional/async-result/async-result.mts +0 -17
- package/src/functional/async-result/impl/async-result-flat-map.mts +0 -99
- package/src/functional/async-result/impl/async-result-from-promise.mts +0 -69
- package/src/functional/async-result/impl/async-result-from-throwable.mts +0 -78
- package/src/functional/async-result/impl/async-result-map-err.mts +0 -84
- package/src/functional/async-result/impl/async-result-map.mts +0 -94
- package/src/functional/async-result/impl/async-result-unwrap-or.mts +0 -42
- package/src/functional/async-result/impl/index.mts +0 -7
- package/src/functional/async-result/impl/types.mts +0 -51
- package/src/functional/async-result/index.mts +0 -1
- package/src/functional/async-result.test.mts +0 -291
- package/src/functional/match.mts +0 -193
- package/src/functional/match.test.mts +0 -180
- package/src/functional/optional/impl/index.mts +0 -18
- package/src/functional/optional/impl/optional-expect-to-be.mts +0 -75
- package/src/functional/optional/impl/optional-filter.mts +0 -78
- package/src/functional/optional/impl/optional-flat-map.mts +0 -75
- package/src/functional/optional/impl/optional-from-nullable.mts +0 -31
- package/src/functional/optional/impl/optional-is-none.mts +0 -26
- package/src/functional/optional/impl/optional-is-optional.mts +0 -30
- package/src/functional/optional/impl/optional-is-some.mts +0 -27
- package/src/functional/optional/impl/optional-map.mts +0 -90
- package/src/functional/optional/impl/optional-match.mts +0 -108
- package/src/functional/optional/impl/optional-none.mts +0 -20
- package/src/functional/optional/impl/optional-or-else.mts +0 -83
- package/src/functional/optional/impl/optional-some.mts +0 -27
- package/src/functional/optional/impl/optional-to-nullable.mts +0 -34
- package/src/functional/optional/impl/optional-unwrap-or.mts +0 -70
- package/src/functional/optional/impl/optional-unwrap-throw.mts +0 -41
- package/src/functional/optional/impl/optional-unwrap.mts +0 -45
- package/src/functional/optional/impl/optional-zip.mts +0 -44
- package/src/functional/optional/impl/tag.mts +0 -8
- package/src/functional/optional/impl/types.mts +0 -31
- package/src/functional/optional/index.mts +0 -1
- package/src/functional/optional/optional.mts +0 -19
- package/src/functional/optional.test.mts +0 -883
- package/src/functional/pipe.mts +0 -180
- package/src/functional/pipe.test.mts +0 -155
- package/src/functional/result/impl/index.mts +0 -27
- package/src/functional/result/impl/result-err.mts +0 -33
- package/src/functional/result/impl/result-expect-to-be.mts +0 -73
- package/src/functional/result/impl/result-flat-map.mts +0 -88
- package/src/functional/result/impl/result-fold.mts +0 -102
- package/src/functional/result/impl/result-from-optional.mts +0 -80
- package/src/functional/result/impl/result-from-promise.mts +0 -51
- package/src/functional/result/impl/result-from-throwable.mts +0 -48
- package/src/functional/result/impl/result-is-err.mts +0 -26
- package/src/functional/result/impl/result-is-ok.mts +0 -26
- package/src/functional/result/impl/result-is-result.mts +0 -28
- package/src/functional/result/impl/result-map-err.mts +0 -96
- package/src/functional/result/impl/result-map.mts +0 -96
- package/src/functional/result/impl/result-match.mts +0 -108
- package/src/functional/result/impl/result-ok.mts +0 -33
- package/src/functional/result/impl/result-or-else.mts +0 -73
- package/src/functional/result/impl/result-safe-try.mts +0 -110
- package/src/functional/result/impl/result-safe-unwrap.mts +0 -50
- package/src/functional/result/impl/result-swap.mts +0 -31
- package/src/functional/result/impl/result-to-optional.mts +0 -37
- package/src/functional/result/impl/result-unwrap-err-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-err-throw.mts +0 -56
- package/src/functional/result/impl/result-unwrap-err.mts +0 -38
- package/src/functional/result/impl/result-unwrap-ok-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-ok.mts +0 -39
- package/src/functional/result/impl/result-unwrap-throw.mts +0 -46
- package/src/functional/result/impl/result-zip.mts +0 -42
- package/src/functional/result/impl/tag.mts +0 -8
- package/src/functional/result/impl/types.mts +0 -38
- package/src/functional/result/index.mts +0 -1
- package/src/functional/result/result.mts +0 -19
- package/src/functional/result.test.mts +0 -1349
- package/src/functional/ternary-result/impl/index.mts +0 -28
- package/src/functional/ternary-result/impl/tag.mts +0 -17
- package/src/functional/ternary-result/impl/ternary-result-err.mts +0 -21
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +0 -65
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +0 -112
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +0 -102
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +0 -30
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +0 -36
- package/src/functional/ternary-result/impl/ternary-result-is-err.mts +0 -24
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +0 -26
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +0 -32
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +0 -74
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +0 -79
- package/src/functional/ternary-result/impl/ternary-result-map.mts +0 -95
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +0 -22
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +0 -72
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +0 -31
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +0 -54
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +0 -42
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +0 -51
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +0 -39
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +0 -40
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +0 -28
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +0 -61
- package/src/functional/ternary-result/impl/types.mts +0 -46
- package/src/functional/ternary-result/impl/variant-name.mts +0 -18
- package/src/functional/ternary-result/index.mts +0 -1
- package/src/functional/ternary-result/ternary-result.mts +0 -50
- package/src/functional/ternary-result.test.mts +0 -310
- package/src/guard/has-key.test.mts +0 -111
- package/src/guard/is-non-null-object.test.mts +0 -109
- package/src/guard/is-record.test.mts +0 -195
- package/src/guard/key-is-in.test.mts +0 -21
- package/src/others/unknown-to-string.test.mts +0 -295
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../result/index.mjs';
|
|
2
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Maps an `AsyncResult<S, E>` to `AsyncResult<S2, E>` by applying a function
|
|
6
|
-
* to the success value. The mapping function may be synchronous or return a
|
|
7
|
-
* `Promise`; both are handled transparently. If the `AsyncResult` resolves to
|
|
8
|
-
* `Err`, the original `Err` is passed through and the function is not called.
|
|
9
|
-
*
|
|
10
|
-
* If `mapFn` throws or returns a rejecting Promise, the rejection propagates
|
|
11
|
-
* as-is — it is **not** caught and converted into an `Err`. `map` performs no
|
|
12
|
-
* implicit error conversion; write a fallible step as
|
|
13
|
-
* `AsyncResult.flatMap` combined with `AsyncResult.fromThrowable` instead, so
|
|
14
|
-
* that the error type stays explicit.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const okValue = AsyncResult.fromPromise(
|
|
20
|
-
* Promise.resolve(5),
|
|
21
|
-
* () => 'failed',
|
|
22
|
-
* );
|
|
23
|
-
*
|
|
24
|
-
* const doubled = await AsyncResult.map(okValue, (value) => value * 2);
|
|
25
|
-
*
|
|
26
|
-
* assert.deepStrictEqual(doubled, Result.ok(10));
|
|
27
|
-
*
|
|
28
|
-
* const double = AsyncResult.map((value: number) => value * 2);
|
|
29
|
-
*
|
|
30
|
-
* const curried = await double(
|
|
31
|
-
* AsyncResult.fromPromise(Promise.resolve(21), () => 'failed'),
|
|
32
|
-
* );
|
|
33
|
-
*
|
|
34
|
-
* assert.deepStrictEqual(curried, Result.ok(42));
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @template S The type of the success value of the input.
|
|
38
|
-
* @template S2 The type of the success value returned by the mapping
|
|
39
|
-
* function.
|
|
40
|
-
* @template E The type of the error value.
|
|
41
|
-
* @param asyncResult The `AsyncResult` to map.
|
|
42
|
-
* @param mapFn The function to apply to the success value if present.
|
|
43
|
-
* @returns A new `AsyncResult<S2, E>`.
|
|
44
|
-
*/
|
|
45
|
-
export function map<S, S2, E>(
|
|
46
|
-
asyncResult: AsyncResult<S, E>,
|
|
47
|
-
mapFn: (value: S) => Promise<S2> | S2,
|
|
48
|
-
): AsyncResult<S2, E>;
|
|
49
|
-
|
|
50
|
-
// Curried version
|
|
51
|
-
//
|
|
52
|
-
// Unlike `Result.map`, the returned function can simply be generic over `E`:
|
|
53
|
-
// an `AsyncResult` is a `Promise`, not a discriminated union, so there is no
|
|
54
|
-
// literal-narrowing problem that would require the whole-result generic
|
|
55
|
-
// trick used by the synchronous combinators.
|
|
56
|
-
export function map<S, S2>(
|
|
57
|
-
mapFn: (value: S) => Promise<S2> | S2,
|
|
58
|
-
): <E>(asyncResult: AsyncResult<S, E>) => AsyncResult<S2, E>;
|
|
59
|
-
|
|
60
|
-
export function map<S, S2, E>(
|
|
61
|
-
...args:
|
|
62
|
-
| readonly [
|
|
63
|
-
asyncResult: AsyncResult<S, E>,
|
|
64
|
-
mapFn: (value: S) => Promise<S2> | S2,
|
|
65
|
-
]
|
|
66
|
-
| readonly [mapFn: (value: S) => Promise<S2> | S2]
|
|
67
|
-
):
|
|
68
|
-
| AsyncResult<S2, E>
|
|
69
|
-
| ((asyncResult: AsyncResult<S, E>) => AsyncResult<S2, E>) {
|
|
70
|
-
switch (args.length) {
|
|
71
|
-
case 2: {
|
|
72
|
-
// Direct version: first argument is asyncResult
|
|
73
|
-
const [asyncResult, mapFn] = args;
|
|
74
|
-
|
|
75
|
-
return mapImpl(asyncResult, mapFn);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
case 1: {
|
|
79
|
-
// Curried version
|
|
80
|
-
const [mapFn] = args;
|
|
81
|
-
|
|
82
|
-
return (asyncResult: AsyncResult<S, E>) => mapImpl(asyncResult, mapFn);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const mapImpl = async <S, S2, E>(
|
|
88
|
-
asyncResult: AsyncResult<S, E>,
|
|
89
|
-
mapFn: (value: S) => Promise<S2> | S2,
|
|
90
|
-
): AsyncResult<S2, E> => {
|
|
91
|
-
const result = await asyncResult;
|
|
92
|
-
|
|
93
|
-
return Result.isErr(result) ? result : Result.ok(await mapFn(result.value));
|
|
94
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../result/index.mjs';
|
|
2
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Unwraps an `AsyncResult`, resolving to the success value or a default value
|
|
6
|
-
* if it resolves to `Err`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const okValue = AsyncResult.fromPromise(
|
|
12
|
-
* Promise.resolve(10),
|
|
13
|
-
* () => 'failed',
|
|
14
|
-
* );
|
|
15
|
-
*
|
|
16
|
-
* const errValue = AsyncResult.fromPromise(
|
|
17
|
-
* Promise.reject(new Error('boom')),
|
|
18
|
-
* () => 'failed',
|
|
19
|
-
* );
|
|
20
|
-
*
|
|
21
|
-
* assert.isTrue((await AsyncResult.unwrapOr(okValue, 0)) === 10);
|
|
22
|
-
*
|
|
23
|
-
* assert.isTrue((await AsyncResult.unwrapOr(errValue, 0)) === 0);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @template S The type of the success value.
|
|
27
|
-
* @template E The type of the error value.
|
|
28
|
-
* @template D The type of the default value.
|
|
29
|
-
* @param asyncResult The `AsyncResult` to unwrap.
|
|
30
|
-
* @param defaultValue The value to resolve to if `asyncResult` resolves to
|
|
31
|
-
* `Err`.
|
|
32
|
-
* @returns A Promise of the success value if `Ok`, otherwise of
|
|
33
|
-
* `defaultValue`.
|
|
34
|
-
*/
|
|
35
|
-
export const unwrapOr = async <S, E, D>(
|
|
36
|
-
asyncResult: AsyncResult<S, E>,
|
|
37
|
-
defaultValue: D,
|
|
38
|
-
): Promise<D | S> => {
|
|
39
|
-
const result = await asyncResult;
|
|
40
|
-
|
|
41
|
-
return Result.isOk(result) ? result.value : defaultValue;
|
|
42
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './async-result-flat-map.mjs';
|
|
2
|
-
export * from './async-result-from-promise.mjs';
|
|
3
|
-
export * from './async-result-from-throwable.mjs';
|
|
4
|
-
export * from './async-result-map-err.mjs';
|
|
5
|
-
export * from './async-result-map.mjs';
|
|
6
|
-
export * from './async-result-unwrap-or.mjs';
|
|
7
|
-
export * from './types.mjs';
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { type Err, type Ok } from '../../../types.mjs';
|
|
2
|
-
import { type UnknownResult } from '../../result/index.mjs';
|
|
3
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Base type for any `AsyncResult`, used for generic constraints. Represents
|
|
7
|
-
* an `AsyncResult` with unknown success and error types.
|
|
8
|
-
*/
|
|
9
|
-
export type UnknownAsyncResult = AsyncResult<unknown, unknown>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Extracts the success value type `S` from a `Result.Ok<S>`, or from an
|
|
13
|
-
* `AsyncResult` resolving to one. Distributes over unions, so an
|
|
14
|
-
* `Ok<S> | Err<E>` union resolves to `S`.
|
|
15
|
-
*
|
|
16
|
-
* @template R The `Result` or `AsyncResult` type to unwrap.
|
|
17
|
-
*/
|
|
18
|
-
export type UnwrapOk<R extends UnknownAsyncResult | UnknownResult> =
|
|
19
|
-
UnwrapOkImpl<SyncResultOf<R>>;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Extracts the error value type `E` from a `Result.Err<E>`, or from an
|
|
23
|
-
* `AsyncResult` resolving to one. Distributes over unions, so an
|
|
24
|
-
* `Ok<S> | Err<E>` union resolves to `E`.
|
|
25
|
-
*
|
|
26
|
-
* @template R The `Result` or `AsyncResult` type to unwrap.
|
|
27
|
-
*/
|
|
28
|
-
export type UnwrapErr<R extends UnknownAsyncResult | UnknownResult> =
|
|
29
|
-
UnwrapErrImpl<SyncResultOf<R>>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @template R The `Result` or `AsyncResult` type.
|
|
33
|
-
* @internal
|
|
34
|
-
* Resolves an `AsyncResult` to its `Result`, leaving a plain `Result`
|
|
35
|
-
* unchanged. Distributive.
|
|
36
|
-
*/
|
|
37
|
-
type SyncResultOf<R> = R extends Promise<infer P> ? P : R;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @template R The `Result` type to unwrap.
|
|
41
|
-
* @internal
|
|
42
|
-
* Distributive extraction of the `Ok` value type.
|
|
43
|
-
*/
|
|
44
|
-
type UnwrapOkImpl<R> = R extends Ok<infer S> ? S : never;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @template R The `Result` type to unwrap.
|
|
48
|
-
* @internal
|
|
49
|
-
* Distributive extraction of the `Err` value type.
|
|
50
|
-
*/
|
|
51
|
-
type UnwrapErrImpl<R> = R extends Err<infer E> ? E : never;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './async-result.mjs';
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { isError } from '@sindresorhus/is';
|
|
2
|
-
import { AsyncResult as AsyncResultFromEntryPoint } from '../entry-point.mjs';
|
|
3
|
-
import { expectType } from '../expect-type.mjs';
|
|
4
|
-
import { unknownToString } from '../others/index.mjs';
|
|
5
|
-
import { AsyncResult } from './async-result/index.mjs';
|
|
6
|
-
import { Result } from './result/index.mjs';
|
|
7
|
-
|
|
8
|
-
// Fixtures are created through functions so that the success/error types stay
|
|
9
|
-
// unions instead of being narrowed to literal types by const inference.
|
|
10
|
-
const okFixture = (value: number): AsyncResult<number, string> =>
|
|
11
|
-
Promise.resolve(Result.ok(value));
|
|
12
|
-
|
|
13
|
-
const errFixture = (message: string): AsyncResult<number, string> =>
|
|
14
|
-
Promise.resolve(Result.err(message));
|
|
15
|
-
|
|
16
|
-
describe('AsyncResult test', () => {
|
|
17
|
-
describe('fromPromise', () => {
|
|
18
|
-
test('resolved promise becomes Ok', async () => {
|
|
19
|
-
const result = await AsyncResult.fromPromise(
|
|
20
|
-
Promise.resolve(42),
|
|
21
|
-
(error) => `mapped: ${unknownToString(error)}`,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
assert.isTrue(Result.isOk(result));
|
|
25
|
-
|
|
26
|
-
assert.deepStrictEqual(result, Result.ok(42));
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('rejected promise becomes Err with mapError applied', async () => {
|
|
30
|
-
const result = await AsyncResult.fromPromise(
|
|
31
|
-
Promise.reject(new Error('boom')),
|
|
32
|
-
(error) => (isError(error) ? error.message : 'unknown'),
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
assert.isTrue(Result.isErr(result));
|
|
36
|
-
|
|
37
|
-
assert.deepStrictEqual(result, Result.err('boom'));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('resolved promise becomes Ok when mapError is omitted', async () => {
|
|
41
|
-
const result = await AsyncResult.fromPromise(Promise.resolve(42));
|
|
42
|
-
|
|
43
|
-
assert.deepStrictEqual(result, Result.ok(42));
|
|
44
|
-
|
|
45
|
-
expectType<typeof result, Result<number, unknown>>('=');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('rejection reason is carried as-is when mapError is omitted', async () => {
|
|
49
|
-
const error = new Error('boom');
|
|
50
|
-
|
|
51
|
-
const result = await AsyncResult.fromPromise(
|
|
52
|
-
Promise.reject(error).then(() => 42),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
assert.isTrue(Result.isErr(result));
|
|
56
|
-
|
|
57
|
-
assert.deepStrictEqual(result, Result.err(error));
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('fromThrowable', () => {
|
|
62
|
-
test('resolved async function becomes Ok', async () => {
|
|
63
|
-
const result = await AsyncResult.fromThrowable(
|
|
64
|
-
() => Promise.resolve('data'),
|
|
65
|
-
(error) => `mapped: ${unknownToString(error)}`,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
assert.isTrue(Result.isOk(result));
|
|
69
|
-
|
|
70
|
-
assert.deepStrictEqual(result, Result.ok('data'));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('synchronous throw becomes Err with mapError applied', async () => {
|
|
74
|
-
const result = await AsyncResult.fromThrowable(
|
|
75
|
-
(): Promise<number> => {
|
|
76
|
-
throw new Error('sync failure');
|
|
77
|
-
},
|
|
78
|
-
(error) => (isError(error) ? error.message : 'unknown'),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
assert.isTrue(Result.isErr(result));
|
|
82
|
-
|
|
83
|
-
assert.deepStrictEqual(result, Result.err('sync failure'));
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('async rejection becomes Err with mapError applied', async () => {
|
|
87
|
-
const result = await AsyncResult.fromThrowable(
|
|
88
|
-
() => Promise.reject(new Error('async failure')),
|
|
89
|
-
(error) => (isError(error) ? error.message : 'unknown'),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
assert.isTrue(Result.isErr(result));
|
|
93
|
-
|
|
94
|
-
assert.deepStrictEqual(result, Result.err('async failure'));
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('synchronous throw is carried as-is when mapError is omitted', async () => {
|
|
98
|
-
const error = new Error('sync failure');
|
|
99
|
-
|
|
100
|
-
const result = await AsyncResult.fromThrowable((): Promise<number> => {
|
|
101
|
-
throw error;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
assert.deepStrictEqual(result, Result.err(error));
|
|
105
|
-
|
|
106
|
-
expectType<typeof result, Result<number, unknown>>('=');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('async rejection is carried as-is when mapError is omitted', async () => {
|
|
110
|
-
const error = new Error('async failure');
|
|
111
|
-
|
|
112
|
-
const result = await AsyncResult.fromThrowable(() =>
|
|
113
|
-
Promise.reject(error).then(() => 42),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
assert.deepStrictEqual(result, Result.err(error));
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('map', () => {
|
|
121
|
-
test('maps Ok value with a synchronous function', async () => {
|
|
122
|
-
const result = await AsyncResult.map(okFixture(5), (value) => value * 2);
|
|
123
|
-
|
|
124
|
-
assert.deepStrictEqual(result, Result.ok(10));
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('maps Ok value with an asynchronous function', async () => {
|
|
128
|
-
const result = await AsyncResult.map(okFixture(5), (value) =>
|
|
129
|
-
Promise.resolve(value * 3),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
assert.deepStrictEqual(result, Result.ok(15));
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('passes Err through unchanged', async () => {
|
|
136
|
-
let mut_called = false;
|
|
137
|
-
|
|
138
|
-
const result = await AsyncResult.map(errFixture('failure'), (value) => {
|
|
139
|
-
mut_called = true;
|
|
140
|
-
|
|
141
|
-
return value * 2;
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
assert.deepStrictEqual(result, Result.err('failure'));
|
|
145
|
-
|
|
146
|
-
assert.isFalse(mut_called);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test('curried version maps Ok value', async () => {
|
|
150
|
-
const double = AsyncResult.map((value: number) => value * 2);
|
|
151
|
-
|
|
152
|
-
const result = await double(okFixture(21));
|
|
153
|
-
|
|
154
|
-
assert.deepStrictEqual(result, Result.ok(42));
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('curried version passes Err through unchanged', async () => {
|
|
158
|
-
const double = AsyncResult.map((value: number) => value * 2);
|
|
159
|
-
|
|
160
|
-
const result = await double(errFixture('failure'));
|
|
161
|
-
|
|
162
|
-
assert.deepStrictEqual(result, Result.err('failure'));
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe('mapErr', () => {
|
|
167
|
-
test('maps Err value with a synchronous function', async () => {
|
|
168
|
-
const result = await AsyncResult.mapErr(errFixture('failure'), (error) =>
|
|
169
|
-
error.toUpperCase(),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
assert.deepStrictEqual(result, Result.err('FAILURE'));
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test('maps Err value with an asynchronous function', async () => {
|
|
176
|
-
const result = await AsyncResult.mapErr(
|
|
177
|
-
errFixture('failure'),
|
|
178
|
-
(message) => Promise.resolve(message.length),
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
assert.deepStrictEqual(result, Result.err(7));
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('passes Ok through unchanged', async () => {
|
|
185
|
-
let mut_called = false;
|
|
186
|
-
|
|
187
|
-
const result = await AsyncResult.mapErr(okFixture(1), (error) => {
|
|
188
|
-
mut_called = true;
|
|
189
|
-
|
|
190
|
-
return error.toUpperCase();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
assert.deepStrictEqual(result, Result.ok(1));
|
|
194
|
-
|
|
195
|
-
assert.isFalse(mut_called);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('curried version maps Err value', async () => {
|
|
199
|
-
const upper = AsyncResult.mapErr((error: string) => error.toUpperCase());
|
|
200
|
-
|
|
201
|
-
const result = await upper(errFixture('failure'));
|
|
202
|
-
|
|
203
|
-
assert.deepStrictEqual(result, Result.err('FAILURE'));
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
describe('flatMap', () => {
|
|
208
|
-
test('chains with a function returning a Result', async () => {
|
|
209
|
-
const result = await AsyncResult.flatMap(okFixture(4), (value) =>
|
|
210
|
-
value > 0 ? Result.ok(value * 10) : Result.err('non-positive'),
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
assert.deepStrictEqual(result, Result.ok(40));
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test('chains with a function returning an AsyncResult', async () => {
|
|
217
|
-
const result = await AsyncResult.flatMap(okFixture(4), (value) =>
|
|
218
|
-
AsyncResult.fromPromise(Promise.resolve(value + 1), () => 'failed'),
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
assert.deepStrictEqual(result, Result.ok(5));
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('chains into Err returned by the function', async () => {
|
|
225
|
-
const result = await AsyncResult.flatMap(
|
|
226
|
-
okFixture(-1),
|
|
227
|
-
(value): Result<number, string> =>
|
|
228
|
-
value > 0 ? Result.ok(value * 10) : Result.err('non-positive'),
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
assert.deepStrictEqual(result, Result.err('non-positive'));
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
test('short-circuits on Err without calling the function', async () => {
|
|
235
|
-
let mut_called = false;
|
|
236
|
-
|
|
237
|
-
const result = await AsyncResult.flatMap(
|
|
238
|
-
errFixture('failure'),
|
|
239
|
-
(value) => {
|
|
240
|
-
mut_called = true;
|
|
241
|
-
|
|
242
|
-
return Result.ok(value * 2);
|
|
243
|
-
},
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
assert.deepStrictEqual(result, Result.err('failure'));
|
|
247
|
-
|
|
248
|
-
assert.isFalse(mut_called);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test('curried version chains with a function returning a Result', async () => {
|
|
252
|
-
const validate = AsyncResult.flatMap(
|
|
253
|
-
(value: number): Result<number, string> =>
|
|
254
|
-
value > 0 ? Result.ok(value) : Result.err('non-positive'),
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
const passed = await validate(okFixture(7));
|
|
258
|
-
|
|
259
|
-
const failed = await validate(okFixture(-7));
|
|
260
|
-
|
|
261
|
-
assert.deepStrictEqual(passed, Result.ok(7));
|
|
262
|
-
|
|
263
|
-
assert.deepStrictEqual(failed, Result.err('non-positive'));
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
describe('unwrapOr', () => {
|
|
268
|
-
test('returns the success value for Ok', async () => {
|
|
269
|
-
const value = await AsyncResult.unwrapOr(okFixture(10), 0);
|
|
270
|
-
|
|
271
|
-
expect(value).toBe(10);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
test('returns the default value for Err', async () => {
|
|
275
|
-
const value = await AsyncResult.unwrapOr(errFixture('failure'), 0);
|
|
276
|
-
|
|
277
|
-
expect(value).toBe(0);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
describe('entry point', () => {
|
|
282
|
-
test('AsyncResult is exported from the package entry point', async () => {
|
|
283
|
-
const result = await AsyncResultFromEntryPoint.fromPromise(
|
|
284
|
-
Promise.resolve(1),
|
|
285
|
-
() => 'failed',
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
assert.deepStrictEqual(result, Result.ok(1));
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
});
|
package/src/functional/match.mts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ReadonlyRecord,
|
|
3
|
-
type RelaxedExclude,
|
|
4
|
-
type TypeEq,
|
|
5
|
-
type UnknownRecord,
|
|
6
|
-
type ValueOf,
|
|
7
|
-
} from 'ts-type-forge';
|
|
8
|
-
import { expectType } from '../expect-type.mjs';
|
|
9
|
-
import { keyIsIn } from '../guard/index.mjs';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Type-safe pattern matching function for string-based discriminated unions.
|
|
13
|
-
*
|
|
14
|
-
* Provides compile-time guarantees for exhaustive case handling when working
|
|
15
|
-
* with literal string unions. Automatically enforces completeness checking when
|
|
16
|
-
* all cases are covered, and requires a default value when cases are
|
|
17
|
-
* incomplete.
|
|
18
|
-
*
|
|
19
|
-
* ## Key Features:
|
|
20
|
-
*
|
|
21
|
-
* - **Exhaustive Matching**: When all cases of a literal union are handled, no
|
|
22
|
-
* default value is needed
|
|
23
|
-
* - **Partial Matching**: When cases are incomplete or working with general
|
|
24
|
-
* string types, a default value is required
|
|
25
|
-
* - **Type Safety**: Prevents extra cases and ensures only valid keys are used
|
|
26
|
-
* - **Strict Property Checking**: Rejects objects with unexpected properties
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
*
|
|
30
|
-
* ```ts
|
|
31
|
-
* type Status = 'draft' | 'review' | 'published';
|
|
32
|
-
*
|
|
33
|
-
* const status: Status = 'draft';
|
|
34
|
-
*
|
|
35
|
-
* const message = match<
|
|
36
|
-
* Status,
|
|
37
|
-
* Readonly<{ draft: string; review: string; published: string }>
|
|
38
|
-
* >(status, {
|
|
39
|
-
* draft: 'Work in progress',
|
|
40
|
-
* review: 'Awaiting feedback',
|
|
41
|
-
* published: 'Complete',
|
|
42
|
-
* });
|
|
43
|
-
*
|
|
44
|
-
* assert.isTrue(message === 'Work in progress');
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @param target - The value to match against
|
|
48
|
-
* @param cases - Object mapping possible values to their corresponding results
|
|
49
|
-
* @param defaultValue - Fallback value (required when not all cases are
|
|
50
|
-
* covered)
|
|
51
|
-
* @returns The matched result or default value
|
|
52
|
-
*/
|
|
53
|
-
export function match<
|
|
54
|
-
const Case extends string,
|
|
55
|
-
const R extends ReadonlyRecord<Case, unknown>,
|
|
56
|
-
>(target: Case, cases: StrictPropertyCheck<R, Case>): R[Case];
|
|
57
|
-
|
|
58
|
-
export function match<
|
|
59
|
-
const Case extends string,
|
|
60
|
-
const R extends UnknownRecord,
|
|
61
|
-
const D,
|
|
62
|
-
>(
|
|
63
|
-
target: Case,
|
|
64
|
-
cases: StrictPropertyCheck<R, Case>,
|
|
65
|
-
defaultValue: IsLiteralUnionFullyCovered<Case, R> extends true ? never : D,
|
|
66
|
-
): ValueOf<R> | D;
|
|
67
|
-
|
|
68
|
-
export function match<
|
|
69
|
-
const Case extends string,
|
|
70
|
-
const R extends UnknownRecord,
|
|
71
|
-
const D,
|
|
72
|
-
>(
|
|
73
|
-
...args:
|
|
74
|
-
| readonly [target: Case, cases: R]
|
|
75
|
-
| readonly [target: Case, cases: R, defaultValue: D]
|
|
76
|
-
): ValueOf<R> | D {
|
|
77
|
-
switch (args.length) {
|
|
78
|
-
case 2: {
|
|
79
|
-
const [target, cases] = args;
|
|
80
|
-
|
|
81
|
-
return cases[target];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
case 3: {
|
|
85
|
-
const [target, cases, defaultValue] = args;
|
|
86
|
-
|
|
87
|
-
return keyIsIn(target, cases) ? cases[target] : defaultValue;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @template T The object type to check.
|
|
94
|
-
* @template ExpectedKeys The union of string literal types representing the
|
|
95
|
-
* allowed keys.
|
|
96
|
-
* @internal
|
|
97
|
-
* Helper type to ensure that an object `T` only contains keys specified in `ExpectedKeys`.
|
|
98
|
-
* If `T` has any keys not in `ExpectedKeys`, this type resolves to `never`.
|
|
99
|
-
*/
|
|
100
|
-
type StrictPropertyCheck<T, ExpectedKeys extends PropertyKey> =
|
|
101
|
-
RelaxedExclude<keyof T, ExpectedKeys> extends never ? T : never;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @template Case A union of string literal types representing the possible
|
|
105
|
-
* cases.
|
|
106
|
-
* @template R A record type.
|
|
107
|
-
* @internal
|
|
108
|
-
* Helper type to check if all cases in `Case` union are fully covered by keys in `R`.
|
|
109
|
-
* This checks bidirectional coverage: all Case members are in R, and no extra keys.
|
|
110
|
-
*/
|
|
111
|
-
type AllCasesCovered<Case extends PropertyKey, R> =
|
|
112
|
-
TypeEq<Case, keyof R> extends true ? true : false;
|
|
113
|
-
|
|
114
|
-
expectType<AllCasesCovered<'a' | 'b', Readonly<{ a: 1; b: 2 }>>, true>('=');
|
|
115
|
-
|
|
116
|
-
expectType<AllCasesCovered<'a' | 'b' | 'c', Readonly<{ a: 1; b: 2 }>>, false>(
|
|
117
|
-
'=',
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
expectType<AllCasesCovered<'a' | 'b', Readonly<{ a: 1; b: 2; c: 3 }>>, false>(
|
|
121
|
-
'=',
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
expectType<AllCasesCovered<string, ReadonlyRecord<string, string>>, true>('=');
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* @template Case A union of string literal types.
|
|
128
|
-
* @template R A record type.
|
|
129
|
-
* @internal
|
|
130
|
-
* Helper type to check if Case is a literal union type and all cases are covered.
|
|
131
|
-
*/
|
|
132
|
-
type IsLiteralUnionFullyCovered<
|
|
133
|
-
Case extends PropertyKey,
|
|
134
|
-
R extends UnknownRecord,
|
|
135
|
-
> =
|
|
136
|
-
TypeEq<IsLiteralType<Case>, true> extends true
|
|
137
|
-
? AllCasesCovered<Case, R>
|
|
138
|
-
: false;
|
|
139
|
-
|
|
140
|
-
expectType<
|
|
141
|
-
IsLiteralUnionFullyCovered<'a' | 'b', Readonly<{ a: 1; b: 2 }>>,
|
|
142
|
-
true
|
|
143
|
-
>('=');
|
|
144
|
-
|
|
145
|
-
expectType<
|
|
146
|
-
IsLiteralUnionFullyCovered<'a' | 'b' | 'c', Readonly<{ a: 1; b: 2 }>>,
|
|
147
|
-
false
|
|
148
|
-
>('=');
|
|
149
|
-
|
|
150
|
-
expectType<
|
|
151
|
-
IsLiteralUnionFullyCovered<'a' | 'b', Readonly<{ a: 1; b: 2; c: 3 }>>,
|
|
152
|
-
false
|
|
153
|
-
>('=');
|
|
154
|
-
|
|
155
|
-
expectType<
|
|
156
|
-
IsLiteralUnionFullyCovered<string, ReadonlyRecord<string, string>>,
|
|
157
|
-
false
|
|
158
|
-
>('=');
|
|
159
|
-
|
|
160
|
-
expectType<
|
|
161
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
162
|
-
IsLiteralUnionFullyCovered<'a' | 'b' | string, Readonly<{ a: 1; b: 2 }>>,
|
|
163
|
-
false
|
|
164
|
-
>('=');
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @template T The PropertyKey type to check.
|
|
168
|
-
* @returns `true` if `T` is a literal type, `false` otherwise.
|
|
169
|
-
* @internal
|
|
170
|
-
* Helper type to determine if a given PropertyKey `T` is a literal type (e.g., 'a', 1)
|
|
171
|
-
* or a general type (e.g., string, number).
|
|
172
|
-
*/
|
|
173
|
-
type IsLiteralType<T extends PropertyKey> = string extends T
|
|
174
|
-
? false
|
|
175
|
-
: number extends T
|
|
176
|
-
? false
|
|
177
|
-
: symbol extends T
|
|
178
|
-
? false
|
|
179
|
-
: true;
|
|
180
|
-
|
|
181
|
-
expectType<IsLiteralType<'a' | 'b'>, true>('=');
|
|
182
|
-
|
|
183
|
-
expectType<IsLiteralType<'a'>, true>('=');
|
|
184
|
-
|
|
185
|
-
expectType<IsLiteralType<string>, false>('=');
|
|
186
|
-
|
|
187
|
-
expectType<IsLiteralType<number>, false>('=');
|
|
188
|
-
|
|
189
|
-
expectType<IsLiteralType<1>, true>('=');
|
|
190
|
-
|
|
191
|
-
expectType<IsLiteralType<number | 'aa'>, false>('=');
|
|
192
|
-
|
|
193
|
-
expectType<IsLiteralType<'aa' | 32>, true>('=');
|