Skip to content

Commit

Permalink
feat: compatible with keyofStringsOnly (#404)
Browse files Browse the repository at this point in the history
Uses `keyof any` to get `PropertyKey` work on TS 2.9 (keyofStringsOnly)
  • Loading branch information
ikatyang authored Jul 25, 2018
1 parent a0b99a0 commit 6d5b6cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
10 changes: 4 additions & 6 deletions templates/$operation.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Morphism } from './$types';
import { Morphism, PropKey } from './$types';

export type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };

// from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f8fb828/types/ramda/index.d.ts#L64
export type Evolver<T> = Morphism<T, T> | { [K in keyof T]?: Evolver<T[K]> };

// from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
export type Diff<T extends PropertyKey, U extends PropertyKey> = ({
[P in T]: P
} &
export type Diff<T extends PropKey, U extends PropKey> = ({ [P in T]: P } &
{ [P in U]: never } & { [x: string]: never })[T];
export type Omit<T, K extends PropertyKey> = Pick<T, Diff<keyof T, K>>;
export type Omit<T, K extends PropKey> = Pick<T, Diff<keyof T, K>>;

export type Same<T extends PropertyKey, U extends PropertyKey> = Diff<
export type Same<T extends PropKey, U extends PropKey> = Diff<
T | U,
Diff<T, U> | Diff<U, T>
>;
Expand Down
5 changes: 3 additions & 2 deletions templates/$types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export type Property = string | number | symbol;
export type Path = List<Property>;
export type PropKey = keyof any; // for backward compatibility (keyofStringsOnly)

// general

Expand All @@ -14,12 +15,12 @@ export type IndexedListMorphism<T, U> = (
index: number,
list: List<T>,
) => U;
export type IndexedObjectMorphism<T, U, K extends PropertyKey> = (
export type IndexedObjectMorphism<T, U, K extends PropKey> = (
value: T,
index: number,
object: Record<K, T>,
) => U;
export type KeyedObjectMorphism<T, U, K extends PropertyKey> = (
export type KeyedObjectMorphism<T, U, K extends PropKey> = (
value: T,
key: K,
object: Record<K, T>,
Expand Down
4 changes: 2 additions & 2 deletions templates/dissoc.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Omit } from './$operation';
import { Property } from './$types';
import { Property, PropKey } from './$types';

export function $keyof<T extends object, K extends keyof T>(
property: K,
object: T,
): Omit<T, K>;
export function $record<U extends Record<V, any>, V extends PropertyKey>(
export function $record<U extends Record<V, any>, V extends PropKey>(
property: V,
object: U,
): Omit<U, V>;
Expand Down

0 comments on commit 6d5b6cc

Please sign in to comment.