FnHandle
On this page

FnHandle

Type in Authoring

The type fn() returns: a typed, callable handle that is also a FuncDecl.

import type { FnHandle } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

type FnHandle<P extends FnParamSpec, R extends string> = FuncDecl & {
/** Typed object-param call. TypeScript checks the argument names, types and
* completeness. A raw number lifts to the declared parameter type, so a `u32`
* parameter gets a `u32` literal. A struct-handle parameter accepts a forwarded
* field proxy. Arguments are read-only nodes: a call only reads them, so `Let`
* results and expressions are accepted. */
(args: {
readonly [K in keyof P]:
| ReadonlyNode<KeyOf<ParamTypeOf<P[K]>>>
| number
| (P[K] extends StructParamHandle ? StructArg : never);
}): Node<R>;
/** @deprecated Use the object-param call `foo({ a, b })`. The positional form checks
* neither arity nor argument types nor order at the TypeScript level, so two arguments
* of the same type can be swapped without an error; the object form catches all of
* that. A struct field proxy is accepted and unwraps to its struct-value node. */
(...args: (NodeLike | StructArg)[]): Node<R>;
} & { readonly decl: FuncDecl };

Description

The same value makes calls (foo({ a, b })), drops into module({ funcs: [foo] }), and exposes the plain declaration as foo.decl. Use FnHandle<P, R> as a type annotation when a handle built in one place crosses a module boundary as a value other code calls: the params and return key are pinned in the type, so the caller gets the same object-param checking fn()’s own return value gives.

Examples

Example

export type FilterFn = FnHandle<{ v: typeof f32T; level: typeof f32T }, 'bool'>

Source

src/core/ir/builder.ts, line 544, at commit 26de7be8

Edit this page Report a problem