Skip to content

Commit 971282f

Browse files
add examples directory
1 parent 78626fe commit 971282f

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
Reason with TypeScript code via
44
[type introspection](https://en.wikipedia.org/wiki/Type_introspection).
55

6-
TODO: Figure out what else to do next with this such as merging the PR that is
7-
currently open, at least.
6+
## Introspection
7+
8+
Introspection helps avoid the problem of slow types introduced by libraries like
9+
Zod and TypeBox. It allows you to determine the type of a value at runtime,
10+
rather than inferring it at compile time. This can lead to more efficient and
11+
dynamic type handling in your TypeScript projects.
812

913
## Installation
1014

@@ -22,10 +26,18 @@ currently open, at least.
2226
> it has an extremely fast built-in type checker, it can create example values
2327
> based on schemas, and a lot more.
2428
>
25-
> - <https://blog.val.town/blog/typebox/>
29+
> \- <https://blog.val.town/blog/typebox/>
30+
31+
Introspection helps avoid the problem of slow types introduced by libraries like
32+
Zod and TypeBox. It allows you to determine the type of a value at runtime,
33+
rather than inferring it at compile time. This can lead to more efficient and
34+
dynamic type handling in your TypeScript projects.
2635

2736
### TypeBox example
2837

38+
Instantiate a TypeBox schema at runtime using introspection via
39+
`@sinclair/typebox/compiler`.
40+
2941
```ts
3042
// TODO: Add TypeBox example.
3143
```

lib/typebox/schema-from-introspection.test.ts renamed to examples/schema-from-introspection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { TypeCompiler } from "@sinclair/typebox/compiler";
33
import {
44
EXAMPLE_PERSON,
55
EXAMPLE_PERSON_INTROSPECTION,
6-
} from "#/lib/introspector/example/person.ts";
7-
import { schemaFromIntrospection } from "./schema-from-introspection.ts";
6+
} from "#/lib/example/person.ts";
7+
import { schemaFromIntrospection } from "#/lib/typebox/schema-from-introspection.ts";
88

99
Deno.test("schemaFromIntrospection introspects TypeScript class", () => {
1010
const schema = schemaFromIntrospection(EXAMPLE_PERSON_INTROSPECTION);

lib/introspector/tree-sitter-introspector.test.ts renamed to examples/tree-sitter-introspector.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { assertEquals } from "@std/assert";
2-
import { EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER } from "./example/tree-sitter-parser.ts";
2+
import { TreeSitterIntrospector } from "#/lib/introspector/tree-sitter-introspector.ts";
3+
import { EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER } from "../lib/example/tree-sitter-parser.ts";
34
import {
45
EXAMPLE_PERSON_INTROSPECTION,
56
EXAMPLE_PERSON_SOURCE_CODE,
67
Person,
7-
} from "./example/person.ts";
8-
import { TreeSitterIntrospector } from "./tree-sitter-introspector.ts";
8+
} from "#/lib/example/person.ts";
99

1010
Deno.test("TreeSitterIntrospector introspects TypeScript class", () => {
1111
const introspector = new TreeSitterIntrospector(
File renamed without changes.

lib/introspector/example/person.ts renamed to lib/example/person.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { queryRootNode } from "#/lib/tree-sitter/tree-sitter.ts";
22
import type { Introspection } from "#/lib/introspector/introspector.ts";
3-
43
import { makeTreeSitterTypeScriptClassPattern } from "#/lib/introspector/tree-sitter-introspector.ts";
54
import {
65
EXAMPLE_TYPESCRIPT_CLASS_TREE_SITTER_CAPTURE_NAME_MAP,

0 commit comments

Comments
 (0)