-
Notifications
You must be signed in to change notification settings - Fork 71
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
type declarations for typescript #326
Labels
enhancement
New feature or request
Comments
I would be interested in it. I am doing some work using the runtime at the moment and by the time I'm done it is likely I'll have a bunch of type definitions defined. So if it is something the observable team would be interested in accepting I could consider sending through a pull request for it. |
Here's what I've got currently. Might open a PR at some point unless someone else wants to pick it up. declare module 'https://cdn.jsdelivr.net/npm/@observablehq/runtime@5/dist/runtime.js' {
export class Runtime {
constructor(builtins?: Builtins, global?: (name: string | symbol) => unknown)
module(define: NotebookDefine, handler: GetObserver): Module
dispose(): void
}
export class Inspector implements Required<Observer> {
constructor(element: Element)
static into(container: Element | string): () => Inspector
pending(): void
fulfilled(value: unknown, name: string | null): void
rejected(error: unknown, name: string | null): void
}
export class Library implements Builtins {}
export class RuntimeError extends Error {}
class Module {
variable(observer?: Observer): Variable
derive(specifiers: string[], source: Module): Module
define(name: string | null, value: unknown): Variable
define(inputs: string[], getter: (...inputs: unknown[]) => unknown): Variable
define(name: string | null, inputs: string[], getter: (...inputs: unknown[]) => unknown): Variable
import(name: string, module: Module): Variable
import(name: string, alias: string, module: Module): Variable
redefine(name: string, value: unknown): Variable
redefine(name: string, inputs: string[], getter: (...inputs: unknown[]) => unknown): Variable
value(name: string): Variable
}
class Variable {
define(name: string | null, value: unknown): this
define(inputs: string[], getter: (...inputs: unknown[]) => unknown): this
define(name: string | null, inputs: string[], getter: (...inputs: unknown[]) => unknown): this
import(name: string, module: Module): this
import(name: string, alias: string, module: Module): this
delete(): void
}
type Observer = Partial<{
pending(): void
fulfilled(value: unknown, name: string | null): void
rejected(error: unknown, name: string | null): void
}>
type Builtins = Partial<Record<string, unknown>>
type NotebookDefine = (runtime: Runtime, observer: GetObserver) => Module
type GetObserver = (name: string | undefined) => Observer | void
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi 👋 , was wondering if there are, or you're interested in adding type declarations for typescript.
this could be created as a
.d.ts
file here, or added to the https://github.com/DefinitelyTyped/DefinitelyTyped repo.an incipient example of how this would look
The text was updated successfully, but these errors were encountered: