about summary refs log tree commit diff
path: root/src/alf/types.ts
blob: 76ac05d40e3412c2b1a729fdb4350ac8467b5ef7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
type LiteralToCommon<T extends PropertyKey> = T extends number
  ? number
  : T extends string
  ? string
  : T extends symbol
  ? symbol
  : never

/**
 * @see https://stackoverflow.com/questions/68249999/use-as-const-in-typescript-without-adding-readonly-modifiers
 */
export type Mutable<T> = {
  -readonly [K in keyof T]: T[K] extends PropertyKey
    ? LiteralToCommon<T[K]>
    : Mutable<T[K]>
}