Skip to content

Commit

Permalink
fix: mematuhi peraturan ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mednoob committed Mar 12, 2022
1 parent 81213aa commit 05aafde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
21 changes: 10 additions & 11 deletions TypeScriptBasic/0x_Decorators/Decorators.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { StringUtility } from "./Decorators";
import { StringUtility } from './Decorators';

test("[TypeScriptBasic/0x_Decorators] Pengecekan Class Decorator", () => {
expect(new StringUtility(["Test"]).data[0]).toBe("Teks pengganti argumen pertama");
})
test('[TypeScriptBasic/0x_Decorators] Pengecekan Class Decorator', () => {
expect(new StringUtility(['Test']).data[0]).toBe('Teks pengganti argumen pertama');
});

test("[TypeScriptBasic/0x_Decorators] Pengecekan Property Decorator", () => {
// @ts-expect-error
expect(new StringUtility("abc")).toThrowError();
})
test('[TypeScriptBasic/0x_Decorators] Pengecekan Property Decorator', () => {
expect(new StringUtility(['abc'])).toThrowError();
});

test("[TypeScriptBasic/0x_Decorators] Pengecekan Method Decorator", () => {
expect(StringUtility.prototype.sambungData = () => { return "" }).toThrowError();
})
test('[TypeScriptBasic/0x_Decorators] Pengecekan Method Decorator', () => {
expect(StringUtility.prototype.sambungData = () => { return ''; }).toThrowError();
});
13 changes: 7 additions & 6 deletions TypeScriptBasic/0x_Decorators/Decorators.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Penjelasan akan ditulis nanti.

function gantiArgumenConstructor(constructor: typeof StringUtility): any {
function gantiArgumenConstructor(constructor: typeof StringUtility): typeof StringUtility {
return class extends constructor {
constructor(args: string[]) {
super(["Teks pengganti argumen pertama", ...args]);
super(['Teks pengganti argumen pertama', ...args]);
}
}
};
}

function buatMethodTidakDapatDiubah(target: any, key: string, descriptor: PropertyDescriptor) {
function buatMethodTidakDapatDiubah(target: StringUtility, key: string, descriptor: PropertyDescriptor) {
descriptor.writable = false;
}

function harusBerupaArray(target: any, key: string) {
function harusBerupaArray(target: StringUtility, key: string) {
// @ts-expect-error ignore error
if (!Array.isArray(target[key])) {
throw new Error(`${key} harus berupa array`);
}
Expand Down Expand Up @@ -41,4 +42,4 @@ class StringUtility {

export {
StringUtility
}
};

0 comments on commit 05aafde

Please sign in to comment.