Skip to content

Commit

Permalink
refactor(): Improve the type definition of the createUnionType function
Browse files Browse the repository at this point in the history
  • Loading branch information
Karibash committed Mar 1, 2022
1 parent b09e811 commit e458527
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Type } from '@nestjs/common';
import { ResolveTypeFn } from '../../interfaces';

export interface UnionMetadata<T extends Type<unknown>[] = Type<unknown>[]> {
export interface UnionMetadata<T extends readonly Type<unknown>[] = readonly Type<unknown>[]> {
name: string;
typesFn: () => T;
id?: symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TypeMetadataStorage } from '../schema-builder/storages/type-metadata.st
/**
* Interface defining options that can be passed to `createUnionType` function.
*/
export interface UnionOptions<T extends Type<unknown>[] = any[]> {
export interface UnionOptions<T extends readonly Type<unknown>[] = Type<unknown>[]> {
/**
* Name of the union.
*/
Expand All @@ -34,13 +34,13 @@ export interface UnionOptions<T extends Type<unknown>[] = any[]> {

export type ArrayElement<ArrayType extends readonly unknown[]> =
ArrayType[number];
export type Union<T extends any[]> = InstanceType<ArrayElement<T>>;
export type Union<T extends readonly any[]> = InstanceType<ArrayElement<T>>;

/**
* Creates a GraphQL union type composed of types references.
* @param options
*/
export function createUnionType<T extends Type<unknown>[] = any[]>(
export function createUnionType<T extends readonly Type<unknown>[] = Type<unknown>[]>(
options: UnionOptions<T>,
): Union<T> {
const { name, description, types, resolveType } = options;
Expand Down

0 comments on commit e458527

Please sign in to comment.