mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
use type = instead of interface extends
for consistency
This commit is contained in:
committed by
David Lechner
parent
86ae9ab866
commit
802f2bc05d
+2
-2
@@ -108,9 +108,9 @@ export function didFailToWrite(id: number, err: Error): BLEDataDidFailToWriteAct
|
||||
return { type: BLEDataActionType.DidFailToWrite, id, err };
|
||||
}
|
||||
|
||||
export interface BLEDataNotifyAction extends Action<BLEDataActionType.Notify> {
|
||||
export type BLEDataNotifyAction = Action<BLEDataActionType.Notify> & {
|
||||
value: DataView;
|
||||
}
|
||||
};
|
||||
|
||||
export function notify(value: DataView): BLEDataNotifyAction {
|
||||
return { type: BLEDataActionType.Notify, value };
|
||||
|
||||
@@ -27,9 +27,9 @@ export enum EditorActionType {
|
||||
ReloadProgram = 'editor.action.reloadProgram',
|
||||
}
|
||||
|
||||
export interface CurrentEditorAction extends Action<EditorActionType.Current> {
|
||||
export type CurrentEditorAction = Action<EditorActionType.Current> & {
|
||||
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<EditorActionType.Open> {
|
||||
export type EditorOpenAction = Action<EditorActionType.Open> & {
|
||||
/** 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<EditorActionType.StorageChanged> {
|
||||
export type EditorStorageChangedAction = Action<EditorActionType.StorageChanged> & {
|
||||
newValue: string;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an action that indicates the local storage has changed.
|
||||
|
||||
@@ -20,11 +20,10 @@ export enum FlashFirmwareActionType {
|
||||
/**
|
||||
* Action that flashes firmware to a hub.
|
||||
*/
|
||||
export interface FlashFirmwareFlashAction
|
||||
extends Action<FlashFirmwareActionType.FlashFirmware> {
|
||||
export type FlashFirmwareFlashAction = Action<FlashFirmwareActionType.FlashFirmware> & {
|
||||
/** 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<FlashFirmwareActionType.Progress> {
|
||||
export type FlashFirmwareProgressAction = Action<FlashFirmwareActionType.Progress> & {
|
||||
/**
|
||||
* 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 };
|
||||
|
||||
+6
-6
@@ -22,10 +22,11 @@ export enum HubMessageActionType {
|
||||
Checksum = 'hub.message.action.runtime.checksum',
|
||||
}
|
||||
|
||||
export interface HubRuntimeStatusMessageAction
|
||||
extends Action<HubMessageActionType.RuntimeStatus> {
|
||||
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<HubMessageActionType.Checksum> {
|
||||
export type HubChecksumMessageAction = Action<HubMessageActionType.Checksum> & {
|
||||
readonly checksum: number;
|
||||
}
|
||||
};
|
||||
|
||||
export function checksum(checksum: number): HubChecksumMessageAction {
|
||||
return {
|
||||
|
||||
@@ -56,10 +56,11 @@ export function connect(): BootloaderConnectionConnectAction {
|
||||
return { type: BootloaderConnectionActionType.Connect };
|
||||
}
|
||||
|
||||
export interface BootloaderConnectionDidConnectAction
|
||||
extends Action<BootloaderConnectionActionType.DidConnect> {
|
||||
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<BootloaderConnectionActionType.DidFailToConnect> {
|
||||
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<BootloaderConnectionActionType.DidError> {
|
||||
export type BootloaderConnectionDidErrorAction = Action<
|
||||
BootloaderConnectionActionType.DidError
|
||||
> & {
|
||||
err: Error;
|
||||
}
|
||||
};
|
||||
|
||||
export function didError(err: Error): BootloaderConnectionDidErrorAction {
|
||||
return { type: BootloaderConnectionActionType.DidError, err };
|
||||
}
|
||||
|
||||
export interface BootloaderConnectionSendAction
|
||||
extends Action<BootloaderConnectionActionType.Send> {
|
||||
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<BootloaderConnectionActionType.DidSend> {
|
||||
export type BootloaderConnectionDidSendAction = Action<
|
||||
BootloaderConnectionActionType.DidSend
|
||||
> & {
|
||||
err?: Error;
|
||||
}
|
||||
};
|
||||
|
||||
export function didSend(err?: Error): BootloaderConnectionDidSendAction {
|
||||
return { type: BootloaderConnectionActionType.DidSend, err };
|
||||
}
|
||||
|
||||
export interface BootloaderConnectionDidReceiveAction
|
||||
extends Action<BootloaderConnectionActionType.DidReceive> {
|
||||
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<T extends BootloaderRequestActionType>
|
||||
extends Action<T> {
|
||||
type BaseBootloaderRequestAction<T extends BootloaderRequestActionType> = Action<T> & {
|
||||
/**
|
||||
* 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<BootloaderRequestActionType.Program> {
|
||||
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<BootloaderRequestActionType.Init> {
|
||||
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<BootloaderDidRequestType> {
|
||||
export type BootloaderDidRequestAction = Action<BootloaderDidRequestType> & {
|
||||
/**
|
||||
* The unique identifier of the action.
|
||||
*/
|
||||
@@ -347,7 +354,7 @@ export interface BootloaderDidRequestAction extends Action<BootloaderDidRequestT
|
||||
* The error on failure or undefined on success.
|
||||
*/
|
||||
err?: Error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an action that indicates a request was sent or failed to send.
|
||||
@@ -371,20 +378,22 @@ export enum BootloaderResponseActionType {
|
||||
Error = 'bootloader.action.response.error',
|
||||
}
|
||||
|
||||
export interface BootloaderEraseResponseAction
|
||||
extends Action<BootloaderResponseActionType.Erase> {
|
||||
export type BootloaderEraseResponseAction = Action<
|
||||
BootloaderResponseActionType.Erase
|
||||
> & {
|
||||
result: Result;
|
||||
}
|
||||
};
|
||||
|
||||
export function eraseResponse(result: Result): BootloaderEraseResponseAction {
|
||||
return { type: BootloaderResponseActionType.Erase, result };
|
||||
}
|
||||
|
||||
export interface BootloaderProgramResponseAction
|
||||
extends Action<BootloaderResponseActionType.Program> {
|
||||
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<BootloaderResponseActionType.Init> {
|
||||
export type BootloaderInitResponseAction = Action<BootloaderResponseActionType.Init> & {
|
||||
result: Result;
|
||||
}
|
||||
};
|
||||
|
||||
export function initResponse(result: Result): BootloaderInitResponseAction {
|
||||
return { type: BootloaderResponseActionType.Init, result };
|
||||
}
|
||||
|
||||
export interface BootloaderInfoResponseAction
|
||||
extends Action<BootloaderResponseActionType.Info> {
|
||||
export type BootloaderInfoResponseAction = Action<BootloaderResponseActionType.Info> & {
|
||||
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<BootloaderResponseActionType.Checksum> {
|
||||
export type BootloaderChecksumResponseAction = Action<
|
||||
BootloaderResponseActionType.Checksum
|
||||
> & {
|
||||
checksum: number;
|
||||
}
|
||||
};
|
||||
|
||||
export function checksumResponse(checksum: number): BootloaderChecksumResponseAction {
|
||||
return { type: BootloaderResponseActionType.Checksum, checksum };
|
||||
}
|
||||
|
||||
export interface BootloaderStateResponseAction
|
||||
extends Action<BootloaderResponseActionType.State> {
|
||||
export type BootloaderStateResponseAction = Action<
|
||||
BootloaderResponseActionType.State
|
||||
> & {
|
||||
level: ProtectionLevel;
|
||||
}
|
||||
};
|
||||
|
||||
export function stateResponse(level: ProtectionLevel): BootloaderStateResponseAction {
|
||||
return { type: BootloaderResponseActionType.State, level };
|
||||
}
|
||||
|
||||
export interface BootloaderErrorResponseAction
|
||||
extends Action<BootloaderResponseActionType.Error> {
|
||||
export type BootloaderErrorResponseAction = Action<
|
||||
BootloaderResponseActionType.Error
|
||||
> & {
|
||||
command: Command;
|
||||
}
|
||||
};
|
||||
|
||||
export function errorResponse(command: Command): BootloaderErrorResponseAction {
|
||||
return { type: BootloaderResponseActionType.Error, command };
|
||||
|
||||
+6
-7
@@ -10,31 +10,30 @@ export enum MpyActionType {
|
||||
}
|
||||
|
||||
/** Action that requests that a script is compiled. */
|
||||
export interface MpyCompileAction extends Action<MpyActionType.Compile> {
|
||||
export type MpyCompileAction = Action<MpyActionType.Compile> & {
|
||||
/** 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<MpyActionType.DidCompile> {
|
||||
export type MpyDidCompileAction = Action<MpyActionType.DidCompile> & {
|
||||
/** The compiled .mpy file. */
|
||||
readonly data: Uint8Array;
|
||||
}
|
||||
};
|
||||
|
||||
export function didCompile(data: Uint8Array): MpyDidCompileAction {
|
||||
return { type: MpyActionType.DidCompile, data };
|
||||
}
|
||||
|
||||
export interface MpyDidFailToCompileAction
|
||||
extends Action<MpyActionType.DidFailToCompile> {
|
||||
export type MpyDidFailToCompileAction = Action<MpyActionType.DidFailToCompile> & {
|
||||
/** Error output. */
|
||||
readonly err: string;
|
||||
}
|
||||
};
|
||||
|
||||
export function didFailToCompile(err: string): MpyDidFailToCompileAction {
|
||||
return { type: MpyActionType.DidFailToCompile, err };
|
||||
|
||||
@@ -17,7 +17,7 @@ export enum NotificationActionType {
|
||||
|
||||
export type NotificationLevel = 'error' | 'warning' | 'info';
|
||||
|
||||
export interface NotificationAddAction extends Action<NotificationActionType.Add> {
|
||||
export type NotificationAddAction = Action<NotificationActionType.Add> & {
|
||||
/**
|
||||
* Unique ID for this notification instance.
|
||||
*/
|
||||
@@ -34,15 +34,14 @@ export interface NotificationAddAction extends Action<NotificationActionType.Add
|
||||
* URL for help or more information.
|
||||
*/
|
||||
readonly helpUrl?: string;
|
||||
}
|
||||
};
|
||||
|
||||
export interface NotificationRemoveAction
|
||||
extends Action<NotificationActionType.Remove> {
|
||||
export type NotificationRemoveAction = Action<NotificationActionType.Remove> & {
|
||||
/**
|
||||
* ID of an existing notification.
|
||||
*/
|
||||
readonly id: number;
|
||||
}
|
||||
};
|
||||
|
||||
export type NotificationAction = NotificationAddAction | NotificationRemoveAction;
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ export enum ServiceWorkerActionType {
|
||||
Success = 'serviceWorker.success',
|
||||
}
|
||||
|
||||
export interface ServiceWorkerAction<
|
||||
export type ServiceWorkerAction<
|
||||
T extends ServiceWorkerActionType = ServiceWorkerActionType
|
||||
> extends Action<T> {
|
||||
> = Action<T> & {
|
||||
registration: ServiceWorkerRegistration;
|
||||
}
|
||||
};
|
||||
|
||||
export function update(
|
||||
registration: ServiceWorkerRegistration,
|
||||
|
||||
@@ -18,10 +18,9 @@ export enum TerminalActionType {
|
||||
ReceivedData = 'terminal.action.receiveData',
|
||||
}
|
||||
|
||||
export interface TerminalSetDataSourceAction
|
||||
extends Action<TerminalActionType.SetDataSource> {
|
||||
export type TerminalSetDataSourceAction = Action<TerminalActionType.SetDataSource> & {
|
||||
dataSource: Observable<string>;
|
||||
}
|
||||
};
|
||||
|
||||
export function setDataSource(
|
||||
dataSource: Observable<string>,
|
||||
@@ -29,19 +28,17 @@ export function setDataSource(
|
||||
return { type: TerminalActionType.SetDataSource, dataSource };
|
||||
}
|
||||
|
||||
export interface TerminalDataSendDataAction
|
||||
extends Action<TerminalActionType.SendData> {
|
||||
export type TerminalDataSendDataAction = Action<TerminalActionType.SendData> & {
|
||||
value: string;
|
||||
}
|
||||
};
|
||||
|
||||
export function sendData(data: string): TerminalDataSendDataAction {
|
||||
return { type: TerminalActionType.SendData, value: data };
|
||||
}
|
||||
|
||||
export interface TerminalDataReceiveDataAction
|
||||
extends Action<TerminalActionType.ReceivedData> {
|
||||
export type TerminalDataReceiveDataAction = Action<TerminalActionType.ReceivedData> & {
|
||||
value: string;
|
||||
}
|
||||
};
|
||||
|
||||
export function receiveData(data: string): TerminalDataReceiveDataAction {
|
||||
return { type: TerminalActionType.ReceivedData, value: data };
|
||||
|
||||
Reference in New Issue
Block a user