import { describe, expect, test } from '@jest/globals'; import { hasCircularReference, ReceiveType, reflect, ReflectionClass, reflectOrUndefined, resolveReceiveType, typeOf, visit, } from '../src/reflection/reflection.js'; import { assertType, Embedded, Excluded, excludedAnnotation, findMember, Group, groupAnnotation, indexAccess, InlineRuntimeType, isSameType, PrimaryKey, primaryKeyAnnotation, ReflectionKind, ResetAnnotation, resolveTypeMembers, stringifyResolvedType, stringifyType, Type, typeAnnotation, TypeClass, TypeObjectLiteral, TypeProperty, typeToObject, UUID, validationAnnotation, } from '../src/reflection/type.js'; import { isExtendable } from '../src/reflection/extends.js'; import { expectEqualType } from './utils.js'; import { ClassType, TypeAnnotation } from '@deepkit/core'; import { Partial } from '../src/changes.js'; import { MaxLength, MinLength } from '../src/validator.js'; import { NoTypeReceived } from '../src/utils.js'; //note: this needs to run in a strict TS mode to infer correctly in the IDE type Extends = [A] extends [B] ? true : false; test('stringify primitives', () => { expect(stringifyType(typeOf())).toBe('string'); expect(stringifyType(typeOf())).toBe('number'); expect(stringifyType(typeOf())).toBe('boolean'); expect(stringifyType(typeOf())).toBe('bigint'); expect(stringifyType(typeOf<'a'>())).toBe(`'a'`); expect(stringifyType(typeOf<1>())).toBe(`1`); expect(stringifyType(typeOf())).toBe(`true`); }); test('stringify array', () => { expect(stringifyType(typeOf())).toBe('Array'); expect(stringifyType(typeOf())).toBe('Array'); }); test('stringify date/set/map', () => { expect(stringifyType(typeOf())).toBe('Date'); expect(stringifyType(typeOf>())).toBe('Map'); expect(stringifyType(typeOf>())).toBe('Set'); }); test('type annotation', () => { type MyAnnotation = { __meta?: never & ['myAnnotation'] }; type Username = string & MyAnnotation; const type = typeOf(); const data = typeAnnotation.getType(type, 'myAnnotation'); expect(data).toEqual(undefined); }); test('type annotation non-flattening', () => { type MyAnnotation = { __meta?: never & ['myAnnotation'] }; type Username = string & MyAnnotation; const type = typeOf(); // we treat Annotation as unique types assertType(type, ReflectionKind.union); expect(type.types.length).toBe(2); expect(stringifyType(type)).toBe('Username | string'); }); test('type annotation with option', () => { type MyAnnotation