Skip to content

index.Function.createTyped

github-actions[bot] edited this page Nov 30, 2026 · 26 revisions

Function: createTyped()

function createTyped<TMap>(): <K>(type, attrs) => TMap[K] & {
  __typename: K;
};

Defined in: packages/graphql-casl/src/subjects.ts:106

Returns a typed(type, attrs) helper bound to a specific subject map.

Type Parameters

TMap

TMap extends Record<string, object>

The subject map, e.g. SubjectMap<Resolvers, ResolversTypes>.

Returns

The typed helper.

<K>(type, attrs) => TMap[K] & { __typename: K; }

Remarks

Call once at the app level to tag plain objects with a required __typename so CASL can classify them — both at runtime (detectSubjectType) and at the type level, where the narrowed __typename makes the object satisfy a typed GraphQLAbility's can/cannot subject parameter.

Example

const typed = createTyped<AppSubjectMap>();
ability.can('update', typed('User', { id: targetId }));

API Reference

Clone this wiki locally