Skip to content

Commit

Permalink
Merge pull request #311 from jacob-alford/ja/fix-downstream-float-int…
Browse files Browse the repository at this point in the history
…-inferrence

fix: downstream type inference for Float/Int schemas
  • Loading branch information
jacob-alford authored Nov 29, 2023
2 parents 7693030 + 31ca1ba commit 8a81d23
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 18 deletions.
17 changes: 17 additions & 0 deletions docs/float.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Added in v2.0.0
- [MinNegativeFloat (type alias)](#minnegativefloat-type-alias)
- [MinPositiveFloat (type alias)](#minpositivefloat-type-alias)
- [utils](#utils)
- [FloatBrand (interface)](#floatbrand-interface)
- [maxNegativeFloat](#maxnegativefloat)
- [maxPositiveFloat](#maxpositivefloat)
- [minNegativeFloat](#minnegativefloat)
Expand Down Expand Up @@ -102,6 +103,22 @@ Added in v2.0.0
# utils
## FloatBrand (interface)
A brand for bounded floats.
**Signature**
```ts
export interface FloatBrand<Min extends number, Max extends number> {
readonly Float: unique symbol
readonly Min: Min
readonly Max: Max
}
```

Added in v2.2.1

## maxNegativeFloat

The largest negative float in JavaScript.
Expand Down
17 changes: 17 additions & 0 deletions docs/integer.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Added in v2.0.0
- [MaxSafeInt (type alias)](#maxsafeint-type-alias)
- [MinSafeInt (type alias)](#minsafeint-type-alias)
- [utils](#utils)
- [IntBrand (interface)](#intbrand-interface)
- [maxSafeInt](#maxsafeint)
- [minSafeInt](#minsafeint)

Expand Down Expand Up @@ -74,6 +75,22 @@ Added in v2.0.0
# utils
## IntBrand (interface)
A brand for bounded integers.
**Signature**
```ts
export interface IntBrand<Min extends number, Max extends number> {
readonly Int: unique symbol
readonly Min: Min
readonly Max: Max
}
```

Added in v2.2.1

## maxSafeInt

The largest safe integer in JavaScript.
Expand Down
30 changes: 15 additions & 15 deletions docs/schemata/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ has_children: true

### String (17)

* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `{b;~$D `, `U;o>x2,o`, `sM9n,`)
* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `3/+03/MTc4I++h+7973////5/m+F/vi/+/jSuw==`, `Fve2+i04/+/5`, `+++/1714w/++7/Lv`)
* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `Y_ww-6D_`, `s_r_Xy0_sj`, `-AC--y--`)
* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `bc1c2dsca37vzb3a312xe47h6n3d2z`, `bc1exbc71d4lb8a88ncyecmb1b857l63dyn`, `2iAUJK4ERBid1CPN6zvQeKQSmGFGd`)
* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `~J ~q`, `~J,wz`, `PqDBBprF`)
* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `2+080/==`, `/+9WA++5r/Dh5/m/d+++cy/L7+M+b/c/+em=`, `+8hfcw9/vp/69B/+/L5+Q/Vst0+6/t8AXt/9l+2/+3+=`)
* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `___o-r`, `aBQ0-vH8b2`, `_5__-cy`)
* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `bc136563gz8vhr460d9v74798t4zxs`, `3HiWCyLk8KJLCXsYpENHMVZJ6T`, `bc10unz1312w32060aeb08nb3a70`)
* CamelCaseString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CamelCaseString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CamelCaseString.ts)) (e.g: `Camel_case-string``camelCaseString`)
* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `2293037513430698`, `8289225972708943`, `35290351306910219`)
* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `"ࠠ䐵濶柃釕"@.-7.K-ha.-a.yesJOqw--m.Jl0-vgp-yz.qbU`, `"伌卉똰傴釋핑￷"@[976.69.06.091]`, `|@-CH7.OdUhVavBrw`)
* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0xa6CbfBfDaB3bfcbB3abCCfBAeFDeD1bb6205fd9C`, `0x00ef0c969FB6fdAb4c1FC6Efcd2dB1ebDf9baeFc`, `0xCAf3BFFdFc3Fe1DDcAcBDa6f7eaAC9EaD9EBA31e`)
* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `C0DEcd`, `dC1f45Da`, `7D91CB`)
* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `0H3CF0ad`, `B5D8aAfDb`, `2B6ceB`)
* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsl(662021862513,0000000000.480837%,+000000000100e5%)`, `hsl(98819.9887136e9448688279,000000.0351%,+0100%)`, `hsl(+.5turn+000.4938336%+.5616749%/118716048%)`)
* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `33B.8-`, `3l4d.pKS-_k_.-`, `4hP--_.DCW_`)
* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `(0,+129)`, `(83.7478188474,-93)`, `90,180.0000`)
* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `(%!C0`, `alueEallvalueOf=`, `182967`)
* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgba(100%,22%,100%,0.184678)`, `rgb(2,209,103)`, `rgba(48%,100%,100%,.26)`)
* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `50833732708233743`, `6284192379929747`, `8213170281778594`)
* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `"㛯఍"@D.43-8yBgu.d--m-070..QiR`, `"팎埤��锹䳵쟏֓徘괐"@[95.8.51.68]`, `%#?={04*t.?{$|{.J@7-C-0LYB.sExzK`)
* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0xA930Fbad182eAFAC68b0bef73cB023CFaBacC1dC`, `0xCBa601eAE7CEA92A5bD5CcaBb7DbedCFaE1AD248`, `0x0BB326BA8C4ABBaa0cdF4CBBC3B6cAEA012aF19a`)
* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `3Da0Af`, `#cedF0A`, `#9A6Cb71b`)
* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `1DdEC1`, `deA3c5E8`, `701BFcb`)
* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsl(.18105356775e4812rad+00000.818%+000.3e+72800620%)`, `hsl(94726650.16679e-68643098000100.000e-97964241525%00000000039e+4400%)`, `hsl(-307.001grad+000100%000100e8595%/38.7)`)
* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `667.f3_7_Q-4_3`, `d_6-iq.._j-_4--`, `i8.-_-`)
* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `(80,180.0000)`, `(-87.37622985102,172)`, `(90,+101)`)
* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `WDr/Da==`, `AentoS==`, `%|^k1b'MmGT`)
* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgba(100%,96%,94%,.356669793547)`, `rgba(100%,92%,100%,1)`, `rgb(98,252,250)`)
* String ([docs](https://jacob-alford.github.io/schemata-ts/schemata/String.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/String.ts))
* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `fE9accDB-eeED-d4e0-7EaA-Cda1F0A6b1Ab`, `1F52a15b-FDDa-D3bf-AC0B-Eb89c1cBbaCf`, `82E435EE-be8B-6BCF-5BfE-deB9BE062B8A`)
* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `7eBBfc14-faEA-2cCA-7DFA-dFcaeC6Be8fb`, `EEdAF38D-dbad-CBac-9b3F-EFd6CA6e51A0`, `80c98c06-B15C-Cca1-F0dC-7a4BBFbe6231`)

### Unit (1)

Expand Down
8 changes: 6 additions & 2 deletions src/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ export type MaxNegativeFloat = -1.7976931348623157e308
*/
export const maxNegativeFloat: MaxNegativeFloat = -Number.MAX_VALUE as MaxNegativeFloat

/** @since 2.0.0 */
interface FloatBrand<Min extends number, Max extends number> {
/**
* A brand for bounded floats.
*
* @since 2.2.1
*/
export interface FloatBrand<Min extends number, Max extends number> {
readonly Float: unique symbol
readonly Min: Min
readonly Max: Max
Expand Down
7 changes: 6 additions & 1 deletion src/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export type MaxSafeInt = 9007199254740991
*/
export const maxSafeInt: MaxSafeInt = Number.MAX_SAFE_INTEGER as MaxSafeInt

interface IntBrand<Min extends number, Max extends number> {
/**
* A brand for bounded integers.
*
* @since 2.2.1
*/
export interface IntBrand<Min extends number, Max extends number> {
readonly Int: unique symbol
readonly Min: Min
readonly Max: Max
Expand Down

0 comments on commit 8a81d23

Please sign in to comment.