-
Notifications
You must be signed in to change notification settings - Fork 13k
Add Oracle Types #43480
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
Add Oracle Types #43480
Conversation
Similar to `Uppercase<S>` and `Lowercase<s>` and so on, add a type `Shell<S extends string>` which runs the string S as a `child_process`, captures its stdout, and produces the string literal type that is the captured output string. For example, `Shell<"echo hello">` is the type `"hello"`.
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
This seems like a totally reasonable idea and implementation. 👍 good job. |
@jcreedcmu can you provide a docx version of the paper? That's the standard in our field. Also the recursiveMappedTypes test now stack overflows. Looks like instantiationDepth=640 was too much for today's node. |
I got around the stack limit with: type MoreDeep = Shell<'tsc ...'> By recursively invoking TS I can get another 640 deep. |
I look forward to watching the presentation during the livestream later tonight~ |
Cool, you can use this to automatically add missing dependencies at compile time. type injector = Shell<`npm install -D @types/missingTypes`> Maybe even some kind of conditional compilation that only loads types if they're going to be used. |
This PR introduces a new feature,
Oracle Types
, which is a variantof the type providers concept from languages like F# and Scala. We
call these Oracles.
This enables features like:
a running database, without requiring a burdensome explicit schema
compilation step.
More details can be found in our companion repository, featuring various demos,
as well as our paper to appear in SIGBOVIK'21. You can also watch the
the conference presentation.
How it works
We have added a new intrinsic called
Shell
that allows calling outto an external type provider, by executing the argument as a shell command.
Usage is quite simple: for example,
will make the type
Today
defined to be equivalent (at time of writing) to the string literal type"2021-04-01\n"
.For a more fully worked example, consider the following approach for
calling out to the well-known Z3 constraint solver.
(This assumes you have
z3
installed and on your executable path)As you can see, Oracle Types provide a simple and powerful way to
extend the TypeScript type system. Their security, safety, and
all-round general reasonableness is almost assuredly guaranteed by the
fact that some unit tests pass, provided you don't think about it too
hard.
To make some of our examples work, we had to bump up the
instantiationDepth
limit. We believe that 640 recursive calls oughtto be good enough for anybody.