From 802f2bc05d5bd75d18a74d0d0705de8f0d405bde Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 11 Jun 2020 11:12:51 -0500 Subject: [PATCH] use type = instead of interface extends for consistency --- src/actions/ble.ts | 4 +- src/actions/editor.ts | 13 ++-- src/actions/flash-firmware.ts | 10 ++- src/actions/hub.ts | 12 ++-- src/actions/lwp3-bootloader.ts | 110 ++++++++++++++++++--------------- src/actions/mpy.ts | 13 ++-- src/actions/notification.ts | 9 ++- src/actions/service-worker.ts | 6 +- src/actions/terminal.ts | 15 ++--- 9 files changed, 97 insertions(+), 95 deletions(-) diff --git a/src/actions/ble.ts b/src/actions/ble.ts index 7292db58..68d39895 100644 --- a/src/actions/ble.ts +++ b/src/actions/ble.ts @@ -108,9 +108,9 @@ export function didFailToWrite(id: number, err: Error): BLEDataDidFailToWriteAct return { type: BLEDataActionType.DidFailToWrite, id, err }; } -export interface BLEDataNotifyAction extends Action { +export type BLEDataNotifyAction = Action & { value: DataView; -} +}; export function notify(value: DataView): BLEDataNotifyAction { return { type: BLEDataActionType.Notify, value }; diff --git a/src/actions/editor.ts b/src/actions/editor.ts index 815173bd..f26bd6fe 100644 --- a/src/actions/editor.ts +++ b/src/actions/editor.ts @@ -27,9 +27,9 @@ export enum EditorActionType { ReloadProgram = 'editor.action.reloadProgram', } -export interface CurrentEditorAction extends Action { +export type CurrentEditorAction = Action & { editSession: Ace.EditSession | undefined; -} +}; /** * Sets the current (active) edit session. @@ -56,10 +56,10 @@ export function saveAs(): EditorSaveAsAction { /** * Action that opens a file. */ -export interface EditorOpenAction extends Action { +export type EditorOpenAction = Action & { /** The data to save */ data: ArrayBuffer; -} +}; /** * Creates an action to save a file @@ -70,10 +70,9 @@ export function open(data: ArrayBuffer): EditorOpenAction { } /**Action that indicates the local storage has changed. */ -export interface EditorStorageChangedAction - extends Action { +export type EditorStorageChangedAction = Action & { newValue: string; -} +}; /** * Creates an action that indicates the local storage has changed. diff --git a/src/actions/flash-firmware.ts b/src/actions/flash-firmware.ts index 2262681c..c31b86cb 100644 --- a/src/actions/flash-firmware.ts +++ b/src/actions/flash-firmware.ts @@ -20,11 +20,10 @@ export enum FlashFirmwareActionType { /** * Action that flashes firmware to a hub. */ -export interface FlashFirmwareFlashAction - extends Action { +export type FlashFirmwareFlashAction = Action & { /** The firmware zip file data or undefined to get firmware later. */ data?: ArrayBuffer; -} +}; /** * Creates a new action to flash firmware to a hub. @@ -34,8 +33,7 @@ export function flashFirmware(data?: ArrayBuffer): FlashFirmwareFlashAction { return { type: FlashFirmwareActionType.FlashFirmware, data }; } -export interface FlashFirmwareProgressAction - extends Action { +export type FlashFirmwareProgressAction = Action & { /** * The number of bytes that have been flashed so far. */ @@ -44,7 +42,7 @@ export interface FlashFirmwareProgressAction * The total number of bytes to be flashed. */ total: number; -} +}; export function progress(complete: number, total: number): FlashFirmwareProgressAction { return { type: FlashFirmwareActionType.Progress, complete, total }; diff --git a/src/actions/hub.ts b/src/actions/hub.ts index f6cdf256..f0f10726 100644 --- a/src/actions/hub.ts +++ b/src/actions/hub.ts @@ -22,10 +22,11 @@ export enum HubMessageActionType { Checksum = 'hub.message.action.runtime.checksum', } -export interface HubRuntimeStatusMessageAction - extends Action { +export type HubRuntimeStatusMessageAction = Action< + HubMessageActionType.RuntimeStatus +> & { readonly newStatus: HubRuntimeStatusType; -} +}; export function updateStatus( newStatus: HubRuntimeStatusType, @@ -36,10 +37,9 @@ export function updateStatus( }; } -export interface HubChecksumMessageAction - extends Action { +export type HubChecksumMessageAction = Action & { readonly checksum: number; -} +}; export function checksum(checksum: number): HubChecksumMessageAction { return { diff --git a/src/actions/lwp3-bootloader.ts b/src/actions/lwp3-bootloader.ts index cb0342b6..c71bef64 100644 --- a/src/actions/lwp3-bootloader.ts +++ b/src/actions/lwp3-bootloader.ts @@ -56,10 +56,11 @@ export function connect(): BootloaderConnectionConnectAction { return { type: BootloaderConnectionActionType.Connect }; } -export interface BootloaderConnectionDidConnectAction - extends Action { +export type BootloaderConnectionDidConnectAction = Action< + BootloaderConnectionActionType.DidConnect +> & { canWriteWithoutResponse: boolean; -} +}; export function didConnect( canWriteWithoutResponse: boolean, @@ -81,11 +82,12 @@ export enum BootloaderConnectionFailureReason { GattServiceNotFound = 'gatt-service-not-found', } -export interface BootloaderConnectionDidFailToConnectAction - extends Action { +export type BootloaderConnectionDidFailToConnectAction = Action< + BootloaderConnectionActionType.DidFailToConnect +> & { reason: BootloaderConnectionFailureReason; err?: Error; -} +}; export function didFailToConnect( reason: BootloaderConnectionFailureReason, @@ -94,20 +96,22 @@ export function didFailToConnect( return { type: BootloaderConnectionActionType.DidFailToConnect, reason, err }; } -export interface BootloaderConnectionDidErrorAction - extends Action { +export type BootloaderConnectionDidErrorAction = Action< + BootloaderConnectionActionType.DidError +> & { err: Error; -} +}; export function didError(err: Error): BootloaderConnectionDidErrorAction { return { type: BootloaderConnectionActionType.DidError, err }; } -export interface BootloaderConnectionSendAction - extends Action { +export type BootloaderConnectionSendAction = Action< + BootloaderConnectionActionType.Send +> & { readonly data: ArrayBuffer; readonly withResponse: boolean; -} +}; export function send( data: ArrayBuffer, @@ -116,19 +120,21 @@ export function send( return { type: BootloaderConnectionActionType.Send, data, withResponse }; } -export interface BootloaderConnectionDidSendAction - extends Action { +export type BootloaderConnectionDidSendAction = Action< + BootloaderConnectionActionType.DidSend +> & { err?: Error; -} +}; export function didSend(err?: Error): BootloaderConnectionDidSendAction { return { type: BootloaderConnectionActionType.DidSend, err }; } -export interface BootloaderConnectionDidReceiveAction - extends Action { +export type BootloaderConnectionDidReceiveAction = Action< + BootloaderConnectionActionType.DidReceive +> & { data: DataView; -} +}; export function didReceive(data: DataView): BootloaderConnectionDidReceiveAction { return { type: BootloaderConnectionActionType.DidReceive, data }; @@ -172,13 +178,12 @@ export enum BootloaderRequestActionType { const nextRequestId = createCountFunc(); -interface BaseBootloaderRequestAction - extends Action { +type BaseBootloaderRequestAction = Action & { /** * Unique identifier for this action. */ id: number; -} +}; /** * Action that requests to erase the flash memory. @@ -197,11 +202,12 @@ export function eraseRequest(): BootloaderEraseRequestAction { /** * Action that requests to program the flash memory. */ -export interface BootloaderProgramRequestAction - extends BaseBootloaderRequestAction { +export type BootloaderProgramRequestAction = BaseBootloaderRequestAction< + BootloaderRequestActionType.Program +> & { address: number; payload: ArrayBuffer; -} +}; /** * Creates a request to program the flash memory. @@ -237,10 +243,11 @@ export function rebootRequest(): BootloaderRebootRequestAction { /** * Action that requests to initialize the firmware flashing process. */ -export interface BootloaderInitRequestAction - extends BaseBootloaderRequestAction { +export type BootloaderInitRequestAction = BaseBootloaderRequestAction< + BootloaderRequestActionType.Init +> & { firmwareSize: number; -} +}; /** * Creates a request to initialize the firmware flashing process. @@ -338,7 +345,7 @@ export const BootloaderDidRequestType = 'bootloader.action.did.request'; /** * Action that indicates a request was sent or failed to send. */ -export interface BootloaderDidRequestAction extends Action { +export type BootloaderDidRequestAction = Action & { /** * The unique identifier of the action. */ @@ -347,7 +354,7 @@ export interface BootloaderDidRequestAction extends Action { +export type BootloaderEraseResponseAction = Action< + BootloaderResponseActionType.Erase +> & { result: Result; -} +}; export function eraseResponse(result: Result): BootloaderEraseResponseAction { return { type: BootloaderResponseActionType.Erase, result }; } -export interface BootloaderProgramResponseAction - extends Action { +export type BootloaderProgramResponseAction = Action< + BootloaderResponseActionType.Program +> & { checksum: number; count: number; -} +}; export function programResponse( checksum: number, @@ -393,22 +402,20 @@ export function programResponse( return { type: BootloaderResponseActionType.Program, checksum, count }; } -export interface BootloaderInitResponseAction - extends Action { +export type BootloaderInitResponseAction = Action & { result: Result; -} +}; export function initResponse(result: Result): BootloaderInitResponseAction { return { type: BootloaderResponseActionType.Init, result }; } -export interface BootloaderInfoResponseAction - extends Action { +export type BootloaderInfoResponseAction = Action & { version: number; startAddress: number; endAddress: number; hubType: HubType; -} +}; export function infoResponse( version: number, @@ -425,28 +432,31 @@ export function infoResponse( }; } -export interface BootloaderChecksumResponseAction - extends Action { +export type BootloaderChecksumResponseAction = Action< + BootloaderResponseActionType.Checksum +> & { checksum: number; -} +}; export function checksumResponse(checksum: number): BootloaderChecksumResponseAction { return { type: BootloaderResponseActionType.Checksum, checksum }; } -export interface BootloaderStateResponseAction - extends Action { +export type BootloaderStateResponseAction = Action< + BootloaderResponseActionType.State +> & { level: ProtectionLevel; -} +}; export function stateResponse(level: ProtectionLevel): BootloaderStateResponseAction { return { type: BootloaderResponseActionType.State, level }; } -export interface BootloaderErrorResponseAction - extends Action { +export type BootloaderErrorResponseAction = Action< + BootloaderResponseActionType.Error +> & { command: Command; -} +}; export function errorResponse(command: Command): BootloaderErrorResponseAction { return { type: BootloaderResponseActionType.Error, command }; diff --git a/src/actions/mpy.ts b/src/actions/mpy.ts index 3c4e87a9..7f34be36 100644 --- a/src/actions/mpy.ts +++ b/src/actions/mpy.ts @@ -10,31 +10,30 @@ export enum MpyActionType { } /** Action that requests that a script is compiled. */ -export interface MpyCompileAction extends Action { +export type MpyCompileAction = Action & { /** The script to compile. */ readonly script: string; /** The compiler command line options */ options?: string[]; -} +}; export function compile(script: string, options?: string[]): MpyCompileAction { return { type: MpyActionType.Compile, script, options }; } -export interface MpyDidCompileAction extends Action { +export type MpyDidCompileAction = Action & { /** The compiled .mpy file. */ readonly data: Uint8Array; -} +}; export function didCompile(data: Uint8Array): MpyDidCompileAction { return { type: MpyActionType.DidCompile, data }; } -export interface MpyDidFailToCompileAction - extends Action { +export type MpyDidFailToCompileAction = Action & { /** Error output. */ readonly err: string; -} +}; export function didFailToCompile(err: string): MpyDidFailToCompileAction { return { type: MpyActionType.DidFailToCompile, err }; diff --git a/src/actions/notification.ts b/src/actions/notification.ts index 7207c8c2..9ce438b3 100644 --- a/src/actions/notification.ts +++ b/src/actions/notification.ts @@ -17,7 +17,7 @@ export enum NotificationActionType { export type NotificationLevel = 'error' | 'warning' | 'info'; -export interface NotificationAddAction extends Action { +export type NotificationAddAction = Action & { /** * Unique ID for this notification instance. */ @@ -34,15 +34,14 @@ export interface NotificationAddAction extends Action { +export type NotificationRemoveAction = Action & { /** * ID of an existing notification. */ readonly id: number; -} +}; export type NotificationAction = NotificationAddAction | NotificationRemoveAction; diff --git a/src/actions/service-worker.ts b/src/actions/service-worker.ts index 408a17fe..6f97475d 100644 --- a/src/actions/service-worker.ts +++ b/src/actions/service-worker.ts @@ -8,11 +8,11 @@ export enum ServiceWorkerActionType { Success = 'serviceWorker.success', } -export interface ServiceWorkerAction< +export type ServiceWorkerAction< T extends ServiceWorkerActionType = ServiceWorkerActionType -> extends Action { +> = Action & { registration: ServiceWorkerRegistration; -} +}; export function update( registration: ServiceWorkerRegistration, diff --git a/src/actions/terminal.ts b/src/actions/terminal.ts index f93d9dfb..5ad6c7e1 100644 --- a/src/actions/terminal.ts +++ b/src/actions/terminal.ts @@ -18,10 +18,9 @@ export enum TerminalActionType { ReceivedData = 'terminal.action.receiveData', } -export interface TerminalSetDataSourceAction - extends Action { +export type TerminalSetDataSourceAction = Action & { dataSource: Observable; -} +}; export function setDataSource( dataSource: Observable, @@ -29,19 +28,17 @@ export function setDataSource( return { type: TerminalActionType.SetDataSource, dataSource }; } -export interface TerminalDataSendDataAction - extends Action { +export type TerminalDataSendDataAction = Action & { value: string; -} +}; export function sendData(data: string): TerminalDataSendDataAction { return { type: TerminalActionType.SendData, value: data }; } -export interface TerminalDataReceiveDataAction - extends Action { +export type TerminalDataReceiveDataAction = Action & { value: string; -} +}; export function receiveData(data: string): TerminalDataReceiveDataAction { return { type: TerminalActionType.ReceivedData, value: data };