-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add keyword tables, more content (#1236)
- Loading branch information
1 parent
1fafb80
commit 2569bde
Showing
40 changed files
with
243 additions
and
189 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
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,11 @@ | ||
"use client" | ||
|
||
import { useEffect } from "react" | ||
|
||
export default () => { | ||
useEffect(() => { | ||
window.location.href = "https://discord.com/invite/xEzdc3fJQC" | ||
}, []) | ||
|
||
return null | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { append, entriesOf, flatMorph } from "@ark/util" | ||
import { ark, Generic } from "arktype" | ||
import { arkPrototypes } from "arktype/internal/keywords/constructors.ts" | ||
import type { JSX } from "react" | ||
|
||
const tableNames = [ | ||
"string", | ||
"number", | ||
"other", | ||
"object", | ||
"array", | ||
"FormData", | ||
"TypedArray", | ||
"instanceof", | ||
"generic" | ||
] as const | ||
|
||
type TableName = (typeof tableNames)[number] | ||
|
||
const tableRowsByName = flatMorph(tableNames, (i, name) => [ | ||
name, | ||
[] as JSX.Element[] | ||
]) | ||
|
||
entriesOf(ark.internal.resolutions) | ||
.map( | ||
([alias, v]) => | ||
[alias.endsWith(".root") ? alias.slice(0, -5) : alias, v] as const | ||
) | ||
.sort((l, r) => (l[0] < r[0] ? -1 : 1)) | ||
.forEach(([alias, v]) => { | ||
// should not occur, only for temporary resolutions of cyclic definition | ||
if (typeof v === "string") return | ||
|
||
const name = | ||
alias.startsWith("string") ? "string" | ||
: alias.startsWith("number") ? "number" | ||
: alias.startsWith("FormData") ? "FormData" | ||
: alias.startsWith("Array") ? "array" | ||
: alias.startsWith("object") ? "object" | ||
: alias.startsWith("TypedArray") ? "TypedArray" | ||
: v instanceof Generic ? "generic" | ||
: alias in arkPrototypes ? "instanceof" | ||
: "other" | ||
|
||
tableRowsByName[name] = append( | ||
tableRowsByName[name], | ||
<tr key={alias}> | ||
<td>{alias}</td> | ||
<td>{v.description}</td> | ||
</tr> | ||
) | ||
}) | ||
|
||
export type KeywordTableProps = { | ||
name: TableName | ||
rows: JSX.Element[] | ||
} | ||
|
||
export const KeywordTable = ({ name, rows }: KeywordTableProps) => ( | ||
<> | ||
<h2>{name}</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th className="font-bold">Alias</th> | ||
<th className="font-bold">Description</th> | ||
</tr> | ||
</thead> | ||
<tbody>{...rows}</tbody> | ||
</table> | ||
</> | ||
) | ||
|
||
export const AllKeywordTables = () => | ||
tableNames.map(name => ( | ||
<KeywordTable name={name} rows={tableRowsByName[name]} /> | ||
)) |
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,12 @@ | ||
export default { | ||
betterErrors: | ||
'import { type, type ArkErrors } from "arktype"\n\nconst user = type({\n\tname: "string",\n\tplatform: "\'android\' | \'ios\'",\n\t"versions?": "(number | string)[]"\n})\n\ninterface RuntimeErrors extends ArkErrors {\n\t/**platform must be "android" or "ios" (was "enigma")\nversions[2] must be a number or a string (was bigint)*/\n\tsummary: string\n}\n\nconst narrowMessage = (e: ArkErrors): e is RuntimeErrors => true\n\n// ---cut---\nconst out = user({\n\tname: "Alan Turing",\n\tplatform: "enigma",\n\tversions: [0, "1", 0n]\n})\n\nif (out instanceof type.errors) {\n\t// ---cut-start---\n\tif (!narrowMessage(out)) throw new Error()\n\t// ---cut-end---\n\t// hover summary to see validation errors\n\tconsole.error(out.summary)\n}\n', | ||
clarityAndConcision: | ||
'// @errors: 2322\nimport { type } from "arktype"\n// this file is written in JS so that it can include a syntax error\n// without creating a type error while still displaying the error in twoslash\n// ---cut---\n// hover me\nconst user = type({\n\tname: "string",\n\tplatform: "\'android\' | \'ios\'",\n\t"versions?": "number | string)[]"\n})\n', | ||
deepIntrospectability: | ||
'import { type } from "arktype"\n\nconst user = type({\n\tname: "string",\n\tdevice: {\n\t\tplatform: "\'android\' | \'ios\'",\n\t\t"version?": "number | string"\n\t}\n})\n\n// ---cut---\nuser.extends("object") // true\nuser.extends("string") // false\n// true (string is narrower than unknown)\nuser.extends({\n\tname: "unknown"\n})\n// false (string is wider than "Alan")\nuser.extends({\n\tname: "\'Alan\'"\n})\n', | ||
intrinsicOptimization: | ||
'import { type } from "arktype"\n// prettier-ignore\n// ---cut---\n// all unions are optimally discriminated\n// even if multiple/nested paths are needed\nconst account = type({\n\tkind: "\'admin\'",\n\t"powers?": "string[]"\n}).or({\n\tkind: "\'superadmin\'",\n\t"superpowers?": "string[]"\n}).or({\n\tkind: "\'pleb\'"\n})\n', | ||
unparalleledDx: | ||
'// @noErrors\nimport { type } from "arktype"\n// prettier-ignore\n// ---cut---\nconst user = type({\n\tname: "string",\n\tplatform: "\'android\' | \'ios\'",\n\t"version?": "number | s"\n\t// ^|\n})\n' | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
--- | ||
title: FAQ | ||
sidebar: | ||
order: 4 | ||
--- | ||
|
||
### Why do I see type errors in an ArkType package in `node_modules`? | ||
|
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
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 |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
"integrations", | ||
"scopes", | ||
"generics", | ||
"faq", | ||
"about" | ||
"faq" | ||
] | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"title": "properties", | ||
"pages": [ | ||
"[required](/docs/objects#properties/required)", | ||
"[optional](/docs/objects#properties/optional)", | ||
"[defaultable](/docs/objects#properties/defaultable)", | ||
"[index](/docs/objects#properties/index)", | ||
"[undeclared](/docs/objects#properties/undeclared)", | ||
"[merge](/docs/objects#properties/merge)", | ||
"[keyof](/docs/objects#properties/keyof)", | ||
"[get](/docs/objects#properties/get)" | ||
"[required](/docs/objects#properties-required)", | ||
"[optional](/docs/objects#properties-optional)", | ||
"[defaultable](/docs/objects#properties-defaultable)", | ||
"[index](/docs/objects#properties-index)", | ||
"[undeclared](/docs/objects#properties-undeclared)", | ||
"[merge](/docs/objects#properties-merge)", | ||
"[keyof](/docs/objects#properties-keyof)", | ||
"[get](/docs/objects#properties-get)" | ||
] | ||
} |
Oops, something went wrong.