Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

union and external types #744 #748 #751

Merged
merged 31 commits into from
Jan 31, 2024
Merged

Conversation

miguel-nascimento
Copy link
Contributor

@miguel-nascimento miguel-nascimento commented Jan 31, 2024

Doing another PR since I messed up with the merge order of the older PRs 🤦

Union Types

This PR adds proper support for
literal type

type Input = { kind: "get-config" }
type Input = { digit: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 }`

union type

type Input = { kind: "get-config" | "generate-stuff" }

array of union types

type Input = { scopes: 'view:page' | 'edit:page' | 'create:page' } 

External Types

This PR enable us to import types and use they in the handler function, creating UI using those imported types.

Due to the Issue 1 and a bit of Issue 4, this PR only works with external imports types inside zipper.dev.

How?
The parse function now takes a context: the Project from ts-morph
With this context, we can navigate around, filling holes with type definition from other files.

This context persist after the parser, we're creating the Project once per project

The major issue is the remote imports, we need them in our context too.
We're adding those remote modules when we can't find the module in the local context, then, we check if the import is an external one, if so, we fetch the bundle using the /api/editor/ts/bundle/x?=<specifier> endpoint. [1] [2]

With the remote module in our context, we can proceed to use the compiler to get the definition.

[1] Issue: The import specifier is the raw specifier. The bundle/x endpoint returns specifiers with version, which may be different from the original import specifier, due to the rewrite specifier rules. ❓

[2] Possible issue: We're adding external modules to the Project, but we're not removing the unneeded modules. (not planning to fix it rn)

[3] Issue: External types solving only triggers on the second parse execution, after a keystroke on the editor

[4] Issue: We're not parsing interface A extends B. We can do this later, improving the parse type (concrete, resolved typescript type, and not type node)

* wip

* feat: solve handler types using local imports

* use defaultValue instead of selected

* wip: ready to demo local imports

* wip external

* wip rewrite using go to definition TS api

* dont recreate the project

* wip

* module resoltion for external modules

* try using other methods to get the definition

* fix: create project after zipper project change.

i.e change from `zipper-changelog` to `feature-flag-example`

* wip: parse external types (fully working!)

* wip

* fix: parsing actions

* parseCode -> parseFile

* fix: boot info parse

* fix: app router parse

* fix: schedule modal input parse

* fix: make handle add input work

* fix: explicit fetch origin to get the external bundle

* feat: add support for handler type { foo: ExternalType }

* feat: support for interfaces

* remove satisfies because jest hates it

* fix: unwrap type literal from type declaration

* remove console.log

* fix: await parseActions

* chore: use getZipperDotDevUrl

* clean stuff
Copy link

vercel bot commented Jan 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zipper-run ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2024 8:24pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant