Migrate to official @types/web-bluetooth package

Replace custom Web Bluetooth type declarations with the official
@types/web-bluetooth package from npm. This provides better
maintained and more comprehensive type definitions for the
Web Bluetooth API.

Changes:
- Add @types/web-bluetooth dependency
- Update tsconfig to include web-bluetooth types
- Remove custom src/web-bluetooth.d.ts declarations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Henrik 2025-12-07 12:18:27 +01:00
parent b7ea024df3
commit 9b536e9deb
4 changed files with 9 additions and 126 deletions

7
package-lock.json generated
View file

@ -10,6 +10,7 @@
"dependencies": {
"@heroicons/react": "^2.2.0",
"@tailwindcss/vite": "^4.1.17",
"@types/web-bluetooth": "^0.0.21",
"konva": "^10.0.12",
"pyodide": "^0.27.4",
"react": "^19.2.0",
@ -1543,6 +1544,12 @@
"@types/react": "*"
}
},
"node_modules/@types/web-bluetooth": {
"version": "0.0.21",
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.21.tgz",
"integrity": "sha512-oIQLCGWtcFZy2JW77j9k8nHzAOpqMHLQejDA48XXMWH6tjCQHz5RCFz1bzsmROyL6PUm+LLnUiI4BCn221inxA==",
"license": "MIT"
},
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.48.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.48.0.tgz",

View file

@ -12,6 +12,7 @@
"dependencies": {
"@heroicons/react": "^2.2.0",
"@tailwindcss/vite": "^4.1.17",
"@types/web-bluetooth": "^0.0.21",
"konva": "^10.0.12",
"pyodide": "^0.27.4",
"react": "^19.2.0",

125
src/web-bluetooth.d.ts vendored
View file

@ -1,125 +0,0 @@
// WebBluetooth API type declarations
// https://webbluetoothcg.github.io/web-bluetooth/
interface BluetoothRemoteGATTServer {
device: BluetoothDevice;
connected: boolean;
connect(): Promise<BluetoothRemoteGATTServer>;
disconnect(): void;
getPrimaryService(service: BluetoothServiceUUID): Promise<BluetoothRemoteGATTService>;
getPrimaryServices(service?: BluetoothServiceUUID): Promise<BluetoothRemoteGATTService[]>;
}
interface BluetoothDevice extends EventTarget {
id: string;
name?: string;
gatt?: BluetoothRemoteGATTServer;
watchingAdvertisements: boolean;
watchAdvertisements(options?: WatchAdvertisementsOptions): Promise<void>;
unwatchAdvertisements(): void;
forget(): Promise<void>;
addEventListener(
type: 'gattserverdisconnected' | 'advertisementreceived',
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
): void;
}
interface WatchAdvertisementsOptions {
signal?: AbortSignal;
}
interface BluetoothRemoteGATTService extends EventTarget {
device: BluetoothDevice;
uuid: string;
isPrimary: boolean;
getCharacteristic(characteristic: BluetoothCharacteristicUUID): Promise<BluetoothRemoteGATTCharacteristic>;
getCharacteristics(characteristic?: BluetoothCharacteristicUUID): Promise<BluetoothRemoteGATTCharacteristic[]>;
getIncludedService(service: BluetoothServiceUUID): Promise<BluetoothRemoteGATTService>;
getIncludedServices(service?: BluetoothServiceUUID): Promise<BluetoothRemoteGATTService[]>;
}
interface BluetoothRemoteGATTCharacteristic extends EventTarget {
service: BluetoothRemoteGATTService;
uuid: string;
properties: BluetoothCharacteristicProperties;
value?: DataView;
getDescriptor(descriptor: BluetoothDescriptorUUID): Promise<BluetoothRemoteGATTDescriptor>;
getDescriptors(descriptor?: BluetoothDescriptorUUID): Promise<BluetoothRemoteGATTDescriptor[]>;
readValue(): Promise<DataView>;
writeValue(value: BufferSource): Promise<void>;
writeValueWithResponse(value: BufferSource): Promise<void>;
writeValueWithoutResponse(value: BufferSource): Promise<void>;
startNotifications(): Promise<BluetoothRemoteGATTCharacteristic>;
stopNotifications(): Promise<BluetoothRemoteGATTCharacteristic>;
addEventListener(
type: 'characteristicvaluechanged',
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
): void;
}
interface BluetoothCharacteristicProperties {
broadcast: boolean;
read: boolean;
writeWithoutResponse: boolean;
write: boolean;
notify: boolean;
indicate: boolean;
authenticatedSignedWrites: boolean;
reliableWrite: boolean;
writableAuxiliaries: boolean;
}
interface BluetoothRemoteGATTDescriptor {
characteristic: BluetoothRemoteGATTCharacteristic;
uuid: string;
value?: DataView;
readValue(): Promise<DataView>;
writeValue(value: BufferSource): Promise<void>;
}
interface RequestDeviceOptions {
filters?: BluetoothLEScanFilter[];
optionalServices?: BluetoothServiceUUID[];
acceptAllDevices?: boolean;
}
interface BluetoothLEScanFilter {
services?: BluetoothServiceUUID[];
name?: string;
namePrefix?: string;
manufacturerData?: BluetoothManufacturerDataFilter[];
serviceData?: BluetoothServiceDataFilter[];
}
interface BluetoothManufacturerDataFilter {
companyIdentifier: number;
dataPrefix?: BufferSource;
mask?: BufferSource;
}
interface BluetoothServiceDataFilter {
service: BluetoothServiceUUID;
dataPrefix?: BufferSource;
mask?: BufferSource;
}
type BluetoothServiceUUID = number | string;
type BluetoothCharacteristicUUID = number | string;
type BluetoothDescriptorUUID = number | string;
interface Bluetooth extends EventTarget {
getAvailability(): Promise<boolean>;
requestDevice(options?: RequestDeviceOptions): Promise<BluetoothDevice>;
getDevices(): Promise<BluetoothDevice[]>;
addEventListener(
type: 'availabilitychanged',
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
): void;
}
interface Navigator {
bluetooth: Bluetooth;
}

View file

@ -5,7 +5,7 @@
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"types": ["vite/client"],
"types": ["vite/client", "web-bluetooth"],
"skipLibCheck": true,
/* Bundler mode */