Skip to content

Commit 0ff7143

Browse files
add new blog
1 parent 9f5f91c commit 0ff7143

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

website/blog/typed-napi.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Improve Napi Typing
2+
3+
What's type safety? Why?
4+
5+
https://github.com/ast-grep/ast-grep/issues/1669
6+
https://github.com/ast-grep/ast-grep/issues/48
7+
8+
It guides one to write comprehensive AST code (in case people forget to handle some cases)
9+
10+
# TreeSitter's types
11+
12+
Tree-Sitter's official API is untyped. However it provides static node types in json
13+
14+
1. json hosted by parser library repo
15+
needs type generation(layman's type provider)
16+
2. contains a lot unnamed kinds
17+
You are writing a compiler plugin, not elementary school math homework
18+
3. has alias type
19+
20+
21+
# Big Idea
22+
23+
1. lenient type check if no information
24+
2. more strict checking if refined
25+
26+
27+
# APIs
28+
29+
## Prune unnamed kinds
30+
For example `+`/`-`/`*`/`/` is too noisy for a general AST library
31+
32+
## `ResolveType<M, T>`
33+
34+
Use type script to resolve type alias
35+
36+
## `NodeKinds<M>`
37+
38+
1. string literal completion with string
39+
2. lenient
40+
41+
Problem?
42+
43+
https://github.com/microsoft/TypeScript/issues/33471
44+
https://github.com/microsoft/TypeScript/issues/26277
45+
46+
## Distinguish general `string` and specific kinds
47+
`RefinedNode<>`
48+
49+
50+
## Refine Node, Manually
51+
52+
1.via `sgNode.find<"KIND">`
53+
2.via `sgNode.is<"KIND">`, One time type narrowing
54+
55+
## Refine Node, Automatically
56+
57+
`sgNode.field("kind")`
58+
59+
60+
## Exhaustive Checking via `sgNode.kindForRefinement`
61+
62+
Only available specific kinds
63+
64+
## Typed Rule!
65+
66+
## Opt-in refinement for better compile time performance
67+
68+
# Ending
69+
70+
https://x.com/hd_nvim/status/1868453729940500924
71+
There are very few devs that understands Rust deeply enough and compiler deeply enough that also care about TypeScript in web dev enough to build something for web devs in Rust

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy