Skip to content

Commit

Permalink
add examples directory
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Oct 15, 2024
1 parent 78626fe commit 971282f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
Reason with TypeScript code via
[type introspection](https://en.wikipedia.org/wiki/Type_introspection).

TODO: Figure out what else to do next with this such as merging the PR that is
currently open, at least.
## Introspection

Introspection helps avoid the problem of slow types introduced by libraries like
Zod and TypeBox. It allows you to determine the type of a value at runtime,
rather than inferring it at compile time. This can lead to more efficient and
dynamic type handling in your TypeScript projects.

## Installation

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

### TypeBox example

Instantiate a TypeBox schema at runtime using introspection via
`@sinclair/typebox/compiler`.

```ts
// TODO: Add TypeBox example.
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { TypeCompiler } from "@sinclair/typebox/compiler";
import {
EXAMPLE_PERSON,
EXAMPLE_PERSON_INTROSPECTION,
} from "#/lib/introspector/example/person.ts";
import { schemaFromIntrospection } from "./schema-from-introspection.ts";
} from "#/lib/example/person.ts";
import { schemaFromIntrospection } from "#/lib/typebox/schema-from-introspection.ts";

Deno.test("schemaFromIntrospection introspects TypeScript class", () => {
const schema = schemaFromIntrospection(EXAMPLE_PERSON_INTROSPECTION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { assertEquals } from "@std/assert";
import { EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER } from "./example/tree-sitter-parser.ts";
import { TreeSitterIntrospector } from "#/lib/introspector/tree-sitter-introspector.ts";
import { EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER } from "../lib/example/tree-sitter-parser.ts";
import {
EXAMPLE_PERSON_INTROSPECTION,
EXAMPLE_PERSON_SOURCE_CODE,
Person,
} from "./example/person.ts";
import { TreeSitterIntrospector } from "./tree-sitter-introspector.ts";
} from "#/lib/example/person.ts";

Deno.test("TreeSitterIntrospector introspects TypeScript class", () => {
const introspector = new TreeSitterIntrospector(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { queryRootNode } from "#/lib/tree-sitter/tree-sitter.ts";
import type { Introspection } from "#/lib/introspector/introspector.ts";

import { makeTreeSitterTypeScriptClassPattern } from "#/lib/introspector/tree-sitter-introspector.ts";
import {
EXAMPLE_TYPESCRIPT_CLASS_TREE_SITTER_CAPTURE_NAME_MAP,
Expand Down
File renamed without changes.

0 comments on commit 971282f

Please sign in to comment.