Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/extract-type-date.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fetchium': patch
---

`ExtractType` keeps `Date` as `Date`, so `t.format('date-time')` and `t.format('date')` fields are assignable to `Date`.
3 changes: 3 additions & 0 deletions packages/fetchium/src/__tests__/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ describe('Format System', () => {
// Type check - ExtractType should extract Date
type FormatType = ExtractType<typeof formatType>;
const _typeCheck: FormatType = new Date();
const _assignableToDate: Date = _typeCheck;

// Runtime check - formatType is a number (mask)
expect(typeof formatType).toBe('number');
Expand All @@ -314,6 +315,8 @@ describe('Format System', () => {

const _createdAtCheck: UserCreatedAt = new Date();
const _birthDateCheck: UserBirthDate = new Date();
const _createdAtAsDate: Date = _createdAtCheck;
const _birthDateAsDate: Date = _birthDateCheck;
});
});

Expand Down
9 changes: 6 additions & 3 deletions packages/fetchium/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,12 @@ export type ExtractType<T> =
? ExtractType<U>
: T extends (...args: infer V) => infer Q
? (...args: V) => ExtractType<Q>
: T extends object
? { [K in keyof T]: ExtractType<T[K]> }
: T;
: // Mapping over Date's overloaded methods yields a structural type not assignable to Date.
T extends Date
? T
: T extends object
? { [K in keyof T]: ExtractType<T[K]> }
: T;

export type TypeDefShape = Record<string, TypeDef> | TypeDef;

Expand Down
Loading