Skip to content

Commit

Permalink
refactor: add typescript check noImplicitOverride (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticrake authored Nov 6, 2023
1 parent 30a8421 commit ce95b2d
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 30 deletions.
10 changes: 5 additions & 5 deletions src/bulb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ declare interface Bulb {
class Bulb extends Device {
emitEventsEnabled = true;

protected _sysInfo: BulbSysinfo;
protected override _sysInfo: BulbSysinfo;

/**
* @internal
Expand Down Expand Up @@ -276,14 +276,14 @@ class Bulb extends Device {
* Returns cached results from last retrieval of `system.sysinfo`.
* @returns system.sysinfo
*/
get sysInfo(): BulbSysinfo {
override get sysInfo(): BulbSysinfo {
return this._sysInfo;
}

/**
* @internal
*/
setSysInfo(sysInfo: BulbSysinfo): void {
override setSysInfo(sysInfo: BulbSysinfo): void {
super.setSysInfo(sysInfo);
this.emitEvents();
}
Expand All @@ -300,7 +300,7 @@ class Bulb extends Device {
}

// eslint-disable-next-line class-methods-use-this
get deviceType(): 'bulb' {
override get deviceType(): 'bulb' {
return 'bulb';
}

Expand Down Expand Up @@ -348,7 +348,7 @@ class Bulb extends Device {
* Requests `system.sysinfo` from device.
* @returns parsed JSON response
*/
async getSysInfo(sendOptions?: SendOptions): Promise<BulbSysinfo> {
override async getSysInfo(sendOptions?: SendOptions): Promise<BulbSysinfo> {
const response = await super.getSysInfo(sendOptions);

if (!isBulbSysinfo(response)) {
Expand Down
10 changes: 5 additions & 5 deletions src/bulb/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export interface BulbScheduleRuleInput {

export default class BulbSchedule extends Schedule {
constructor(
readonly device: Bulb,
readonly apiModuleName: string,
readonly childId?: string,
override readonly device: Bulb,
override readonly apiModuleName: string,
override readonly childId?: string,
) {
super(device, apiModuleName, childId);
}
Expand All @@ -49,7 +49,7 @@ export default class BulbSchedule extends Schedule {
* @returns parsed JSON response
* @throws {@link ResponseError}
*/
async addRule(
override async addRule(
rule: BulbScheduleRuleInput,
sendOptions?: SendOptions,
): Promise<{ id: string }> {
Expand All @@ -75,7 +75,7 @@ export default class BulbSchedule extends Schedule {
* @returns parsed JSON response
* @throws {@link ResponseError}
*/
async editRule(
override async editRule(
rule: BulbScheduleRuleInput & { id: string },
sendOptions?: SendOptions,
): Promise<unknown> {
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export default class Client extends EventEmitter implements ClientEventEmitter {
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
emit(eventName: string, ...args: any[]): boolean {
override emit(eventName: string, ...args: any[]): boolean {
// Add device- / plug- / bulb- to eventName
let ret = false;
if (args[0] instanceof Device) {
Expand Down
2 changes: 1 addition & 1 deletion src/network/tcp-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class TcpConnection extends TplinkConnection {
return socket;
}

async send(
override async send(
payload: string,
port: number,
host: string,
Expand Down
2 changes: 1 addition & 1 deletion src/network/tcp-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class TcpSocket extends TplinkSocket {
});
}

close(): void {
override close(): void {
if (this.socket !== undefined) this.socket.end();
super.close();
}
Expand Down
4 changes: 2 additions & 2 deletions src/network/udp-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class UdpConnection extends TplinkConnection {
}
}

async send(
override async send(
payload: string,
port: number,
host: string,
Expand All @@ -76,7 +76,7 @@ export default class UdpConnection extends TplinkConnection {
return response;
}

close(): void {
override close(): void {
super.close();
this.setTimeout(0);

Expand Down
2 changes: 1 addition & 1 deletion src/network/udp-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class UdpSocket extends TplinkSocket {
});
}

close(): void {
override close(): void {
if (this.socket !== undefined) this.socket.close();
super.close();
}
Expand Down
16 changes: 8 additions & 8 deletions src/plug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export interface PlugEventEmitter {
* @fires Plug#emeter-realtime-update
*/
export default class Plug extends Device implements PlugEventEmitter {
protected _sysInfo: PlugSysinfo;
protected override _sysInfo: PlugSysinfo;

#children: Map<string, PlugChild> = new Map();

Expand Down Expand Up @@ -285,14 +285,14 @@ export default class Plug extends Device implements PlugEventEmitter {
}
}

get sysInfo(): PlugSysinfo {
override get sysInfo(): PlugSysinfo {
return this._sysInfo;
}

/**
* @internal
*/
setSysInfo(sysInfo: PlugSysinfo): void {
override setSysInfo(sysInfo: PlugSysinfo): void {
super.setSysInfo(sysInfo);
if (sysInfo.children) {
this.setChildren(sysInfo.children);
Expand Down Expand Up @@ -331,7 +331,7 @@ export default class Plug extends Device implements PlugEventEmitter {
/**
* Returns childId.
*/
get childId(): string | undefined {
override get childId(): string | undefined {
return this.#childId;
}

Expand All @@ -348,7 +348,7 @@ export default class Plug extends Device implements PlugEventEmitter {
/**
* Cached value of `sysinfo.alias` or `sysinfo.children[childId].alias` if childId set.
*/
get alias(): string {
override get alias(): string {
if (this.#childId && this.#child !== undefined) {
return this.#child.alias;
}
Expand All @@ -371,14 +371,14 @@ export default class Plug extends Device implements PlugEventEmitter {
}

// eslint-disable-next-line class-methods-use-this
get deviceType(): 'plug' {
override get deviceType(): 'plug' {
return 'plug';
}

/**
* Cached value of `sysinfo.deviceId` or `childId` if set.
*/
get id(): string {
override get id(): string {
if (this.#childId && this.#child !== undefined) {
return this.#childId;
}
Expand Down Expand Up @@ -463,7 +463,7 @@ export default class Plug extends Device implements PlugEventEmitter {
* Requests `system.sysinfo` from device. Does not support childId.
*/
async getSysInfo(sendOptions?: SendOptions): Promise<PlugSysinfo> {
override async getSysInfo(sendOptions?: SendOptions): Promise<PlugSysinfo> {
const response = await super.getSysInfo(sendOptions);

if (!isPlugSysinfo(response)) {
Expand Down
10 changes: 5 additions & 5 deletions src/plug/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export interface PlugScheduleRuleInput {

export default class PlugSchedule extends Schedule {
constructor(
readonly device: Plug,
readonly apiModuleName: string,
readonly childId?: string,
override readonly device: Plug,
override readonly apiModuleName: string,
override readonly childId?: string,
) {
super(device, apiModuleName, childId);
}
Expand All @@ -47,7 +47,7 @@ export default class PlugSchedule extends Schedule {
* @returns parsed JSON response
* @throws {@link ResponseError}
*/
async addRule(
override async addRule(
rule: PlugScheduleRuleInput,
sendOptions?: SendOptions,
): ReturnType<Schedule['addRule']> {
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class PlugSchedule extends Schedule {
* @returns parsed JSON response
* @throws {@link ResponseError}
*/
async editRule(
override async editRule(
rule: PlugScheduleRuleInput & { id: string },
sendOptions?: SendOptions,
): Promise<unknown> {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ResponseError extends Error {
/**
* Set by `Error.captureStackTrace`
*/
readonly stack = '';
override readonly stack = '';

/**
*
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"declarationMap": true,
"esModuleInterop": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUncheckedIndexedAccess": true,
Expand Down

0 comments on commit ce95b2d

Please sign in to comment.