Skip to content

Commit

Permalink
eclipse-theiaGH-7200: Made RecursivePartial array aware.
Browse files Browse the repository at this point in the history
Closes eclipse-theia#7200.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
  • Loading branch information
Akos Kitta authored and Sean Hellum committed Mar 12, 2020
1 parent 6c10d9b commit 58d6351
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 18 additions & 1 deletion packages/core/src/common/types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,27 @@
********************************************************************************/

import * as assert from 'assert';
import { Prioritizeable } from './types';
import { Prioritizeable, RecursivePartial } from './types';

describe('types', () => {

describe('recursive-partial', () => {
it('should handle nested arrays', () => {
interface Bar {
readonly arr: Array<string>;
}
interface Foo {
readonly bar: Bar;
}
const myArr: Array<string> = [];
const myFoo: RecursivePartial<Foo> = {};
if (myFoo.bar && myFoo.bar.arr) {
const x = Array.from(new Set(myFoo.bar.arr));
myArr.push(...x);
}
});
});

describe('Prioritizeable', () => {
it('prioritizeAll #01', () => {
const input = [-4, 4, -3, 3, -2, 2, -1, 1, 0, -0];
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export type Deferred<T> = {
[P in keyof T]: Promise<T[P]>
};
export type RecursivePartial<T> = {
[P in keyof T]?: RecursivePartial<T[P]>;
[P in keyof T]?: T[P] extends Array<infer I>
? Array<RecursivePartial<I>>
: RecursivePartial<T[P]>;
};
export type MaybeArray<T> = T | T[];
export type MaybePromise<T> = T | Promise<T> | PromiseLike<T>;
Expand Down

0 comments on commit 58d6351

Please sign in to comment.