Skip to content

Commit

Permalink
feat(@angular-devkit/core): add DeepReadonly<> and Readwrite<> types
Browse files Browse the repository at this point in the history
Readwrite removes readonly, while DeepReadonly recursively sets it. A ReadonlyArray
should be used if the type is an array, but that is too much of a change to our API
(JsonValue includes JsonArray but then we would need a ReadonlyJsonValue, and same
for object, which has deep roots in our API).

We should fix this in a further refactor at some point.
  • Loading branch information
hansl authored and mgechev committed Dec 14, 2018
1 parent 64781f6 commit c89a042
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/angular_devkit/core/src/utils/index.ts
Expand Up @@ -16,3 +16,20 @@ export * from './priority-queue';
export * from './lang';

export { tags, strings };

export type DeepReadonly<T> =
T extends (infer R)[] ? DeepReadonlyArray<R> :
T extends Function ? T :
T extends object ? DeepReadonlyObject<T> :
T;

// This should be ReadonlyArray but it has implications.
export interface DeepReadonlyArray<T> extends Array<DeepReadonly<T>> {}

export type DeepReadonlyObject<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};

export type Readwrite<T> = {

This comment has been minimized.

Copy link
@Meligy

Meligy Dec 20, 2018

Contributor

Is this meant to be ReadWrite (uppercase W)?

-readonly [P in keyof T]: T[P];
};

0 comments on commit c89a042

Please sign in to comment.