Skip to content

Commit

Permalink
feat: expose WithId (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
shikaan authored May 18, 2021
1 parent 0d763de commit 80189db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export type {
Items,
Link,
WithOptionalId,
WithId,
} from './utils'

export type { WindowAPI } from './window.types'
1 change: 0 additions & 1 deletion lib/types/space.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* Space API */
import { Entry } from './entry.types'
import {
Asset,
Expand Down
17 changes: 11 additions & 6 deletions lib/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
type SysWithId = {
type Sys = {
id: string
type: string
[key: string]: any
}

export type WithOptionalId<Type extends { sys: unknown }> = Omit<Type, 'sys'> & {
sys?: Partial<Omit<Type['sys'], 'id'> & SysWithId>
type Entity = {
sys: Sys
[key: string]: any
}

export type WithId<Type extends { sys: unknown }> = Omit<Type, 'sys'> & {
sys: Partial<Omit<Type['sys'], 'id'>> & SysWithId
}
type Optional<Type, Keys extends keyof Type> = Partial<Type> & Omit<Type, Keys>

export type WithSysWithAtLeastId = { sys: { id: string; [key: string]: any } }
export type WithId<Type extends Entity> = Omit<Type, 'sys'> & WithSysWithAtLeastId
export type WithOptionalId<Type extends Entity> = Optional<Type, 'sys'> | WithId<Type>

export interface Link<LinkType = string, Type = string> {
sys: {
Expand Down

0 comments on commit 80189db

Please sign in to comment.