FnHandle
타입, 작성 분류
The type fn() returns: a typed, callable handle that is also a FuncDecl.
import type { FnHandle } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
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 };설명
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.
예제
예제
export type FilterFn = FnHandle<{ v: typeof f32T; level: typeof f32T }, 'bool'>소스
src/core/ir/builder.ts, 544행, 커밋 c66579bf 기준