FnHandle
타입, 작성 분류
fn()이 돌려주는 타입입니다. 타입이 지정되고 호출할 수 있는 핸들이며, FuncDecl이기도 합니다.
import type { FnHandle } from 'typeshade'import type { FnHandle } from 'typeshade/core/ir'
설명은 커밋 af54ddad5의 검토된 컴파일러 문서를 번역한 것입니다. 시그니처와 예제 코드는 원문을 따르며, 필요한 경우 설명에 편집상 수정이 반영됩니다.
구문
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 };설명
같은 값으로 호출할 수 있고(foo({ a, b })), module({ funcs: [foo] })에 넣을 수 있으며, 일반 선언은 foo.decl로 꺼낼 수 있습니다. 한 곳에서 만든 핸들이 모듈 경계를 넘어 다른 코드가 호출하는 값으로 전달될 때 FnHandle<P, R>을 타입 주석으로 씁니다. 매개변수와 반환 키가 타입에 고정되므로, 호출하는 쪽은 fn()이 돌려주는 값과 같은 객체 매개변수 검사를 받습니다.
예제
예제
export type FilterFn = FnHandle<{ v: typeof f32T; level: typeof f32T }, 'bool'>소스
src/core/ir/builder.ts, 460행, 커밋 af54ddad5 기준