Skip to content

[I] FunctionContext

Context passed to function implementations.

  • InvocationContext
PropertyTypeDescriptionInherited from
functionCallTargetDiagnosticTargetThe function call diagnostic target.-
programProgramThe current TypeSpec Program.InvocationContext.program
callDecorator<T, A, R>(
decorator,
target, ...
args): R;

Helper to call a decorator implementation from within another decorator implementation.

Type Parameter
T extends Type
A extends any[]
R
ParameterTypeDescription
decorator(context, target, …args) => RThe decorator function to call.
targetTThe target to which the decorator is applied.
argsAArguments to pass to the decorator.

R

InvocationContext.callDecorator

callFunction<A, R>(func, ...args): R;

Helper to call a function implementation from within a decorator implementation.

Type Parameter
A extends any[]
R
ParameterTypeDescription
func(context, …args) => RThe function implementation to call.
argsAArguments to pass to the function.

R

InvocationContext.callFunction

getArgumentTarget(argIndex): DiagnosticTarget | undefined;

Helper to get the target for a given argument index.

ParameterTypeDescription
argIndexnumberArgument index in the decorator call.

DiagnosticTarget | undefined

@dec("hello", 123)
model MyModel { }
  • getArgumentTarget(0) -> target for “hello”
  • getArgumentTarget(1) -> target for 123
InvocationContext.getArgumentTarget