Skip to content

Commit 819bdac

Browse files
committed
Migrate Assets to TS
1 parent a131f8a commit 819bdac

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

generatedTypes/assets/Assets.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export declare class Assets {
2+
[key: string]: any;
3+
loadAssetsGroup(groupName: string, assets: object): this;
4+
}

generatedTypes/assets/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Assets } from './Assets';
2+
declare const _default: Assets;
3+
export default _default;

src/assets/Assets.js renamed to src/assets/Assets.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import _ from 'lodash';
22

3-
function assignProperties(a, b) {
3+
interface CustomObject {[key: string]: any}
4+
5+
function assignProperties(a: CustomObject, b: {[key: string]: any}) {
46
if (a) {
57
_(b).keys().forEach((key) => {
8+
// @ts-ignore
69
Object.defineProperty(a, key, Object.getOwnPropertyDescriptor(b, key));
710
});
811
}
912

1013
return a;
1114
}
1215

13-
function ensurePath(obj, path) {
16+
function ensurePath(obj: CustomObject, path: string) {
1417
let pointer = obj;
1518

1619
const pathArray = path.split('.');
1720
const n = pathArray.length;
1821

1922
for (let i = 0; i < n; i++) {
2023
const segment = pathArray[i];
21-
24+
2225
if (pointer[segment]) {
2326
const descriptor = Object.getOwnPropertyDescriptor(pointer, segment);
24-
if (descriptor.get) {
27+
if (descriptor?.get) {
2528
Object.defineProperty(pointer, segment, descriptor);
2629
}
2730
} else {
@@ -34,7 +37,9 @@ function ensurePath(obj, path) {
3437
}
3538

3639
export class Assets {
37-
loadAssetsGroup(groupName, assets) {
40+
[key: string]: any;
41+
42+
loadAssetsGroup(groupName: string, assets: object) {
3843
if (!_.isString(groupName)) {
3944
throw new Error('group name should be a string');
4045
}
File renamed without changes.

0 commit comments

Comments
 (0)