[Snapping 1/5] Validation & strict types for fractional indexes (#2827)
Currently, we type our fractional index keys as `string` and don't have any validation for them. I'm touching some of this code for my work on line handles and wanted to change that: - fractional indexes are now `IndexKey`s, not `string`s. `IndexKey`s have a brand property so can't be used interchangeably with strings (like our IDs) - There's a new `T.indexKey` validator which we can use in our validations to make sure we don't end up with nonsense keys. This PR is part of a series - please don't merge it until the things before it have landed! 1. #2827 (you are here) 2. #2831 3. #2793 4. #2841 5. #2845 ### Change Type - [x] `patch` — Bug fix ### Test Plan 1. Mostly relying on unit & end to end tests here - no user facing changes. - [x] Unit Tests
This commit is contained in:
parent
fb00358a53
commit
93c2ed615c
40 changed files with 989 additions and 681 deletions
|
@ -1543,6 +1543,43 @@
|
|||
},
|
||||
"implementsTokenRanges": []
|
||||
},
|
||||
{
|
||||
"kind": "Variable",
|
||||
"canonicalReference": "@tldraw/validate!T.indexKey:var",
|
||||
"docComment": "/**\n * Validates that a value is an IndexKey.\n *\n * @public\n */\n",
|
||||
"excerptTokens": [
|
||||
{
|
||||
"kind": "Content",
|
||||
"text": "indexKey: "
|
||||
},
|
||||
{
|
||||
"kind": "Reference",
|
||||
"text": "Validator",
|
||||
"canonicalReference": "@tldraw/validate!Validator:class"
|
||||
},
|
||||
{
|
||||
"kind": "Content",
|
||||
"text": "<"
|
||||
},
|
||||
{
|
||||
"kind": "Reference",
|
||||
"text": "IndexKey",
|
||||
"canonicalReference": "@tldraw/utils!IndexKey:type"
|
||||
},
|
||||
{
|
||||
"kind": "Content",
|
||||
"text": ">"
|
||||
}
|
||||
],
|
||||
"fileUrlPath": "packages/validate/src/lib/validation.ts",
|
||||
"isReadonly": true,
|
||||
"releaseTag": "Public",
|
||||
"name": "indexKey",
|
||||
"variableTypeTokenRange": {
|
||||
"startIndex": 1,
|
||||
"endIndex": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Variable",
|
||||
"canonicalReference": "@tldraw/validate!T.integer:var",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue