Skip to content

Commit d6b93a2

Browse files
committed
Revert "handled case of assets union (#3060)"
This reverts commit 2bff5d1.
1 parent eb0f0e4 commit d6b93a2

File tree

3 files changed

+13
-54
lines changed

3 files changed

+13
-54
lines changed

src/assets/Assets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'lodash';
2-
import type {AssetRecord} from '../typings/assets';
2+
import {PathRecord} from '..//typings/common';
33

44
interface CustomObject {
55
[key: string]: any;
@@ -42,7 +42,7 @@ function ensurePath(obj: CustomObject, path: string) {
4242
export class Assets {
4343
[key: string]: any;
4444

45-
loadAssetsGroup<T extends string, K extends object>(groupName: T, assets: K): asserts this is AssetRecord<typeof this, T, K> {
45+
loadAssetsGroup<T extends string, K extends object>(groupName: T, assets: K): asserts this is PathRecord<T, K> {
4646
if (!_.isString(groupName)) {
4747
throw new Error('group name should be a string');
4848
}

src/typings/assets.d.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/typings/common.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ export type ExtendTypeWith<T extends Constructor<any>, OtherObject extends objec
1010
export type Dictionary<TYPE> = {[key: string]: TYPE};
1111

1212
export type ComponentStatics<T> = Pick<T, keyof T>;
13+
14+
type DotExtendedString<T extends string> = `${T}.`;
15+
export type PathArray<S extends string> = DotExtendedString<S> extends `${infer A}.${infer B}` ?
16+
A extends '' ? [] : [A, ...PathArray<B>]
17+
: [];
18+
19+
export type RecRecord<Path extends string[], K = {}> = Path extends [infer Next, ...infer Rest] ?
20+
{[P in Next] : RecRecord<Rest, K>}
21+
: K;
22+
23+
export type PathRecord<T extends string, K = {}> = RecRecord<PathArray<T>, K>;

0 commit comments

Comments
 (0)