Add type declarations for WebSerial

WebSerial is only available in Chrome Dev, so its type declarations have to be added manually for now. When WebSerial is released, these declarations should be removed.

The declarations are from https://github.com/GoogleChromeLabs/serial-terminal/blob/master/src/serial.d.ts

Change-Id: Iabb875b4586c7f07e63e50c05e274c78ea38ed30
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index b7ee2fc..4774f2f 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -200,6 +200,7 @@
     r'\bgo.(mod|sum)$',
     r'\bpackage.json$',
     r'\byarn.lock$',
+    r'\bpw_web_ui/types/serial.d.ts$',
 )
 
 
diff --git a/pw_web_ui/types/BUILD b/pw_web_ui/types/BUILD
new file mode 100644
index 0000000..217767f
--- /dev/null
+++ b/pw_web_ui/types/BUILD
@@ -0,0 +1,24 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+package(default_visibility = ["//visibility:public"])
+
+load("@npm_bazel_typescript//:index.bzl", "ts_library")
+
+ts_library(
+    name = "serial_lib",
+    srcs = [
+        "serial.d.ts",
+    ],
+)
diff --git a/pw_web_ui/types/serial.d.ts b/pw_web_ui/types/serial.d.ts
new file mode 100644
index 0000000..093466d
--- /dev/null
+++ b/pw_web_ui/types/serial.d.ts
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2019 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** @see https://wicg.github.io/serial/#paritytype-enum */
+type ParityType = 'none' | 'even' | 'odd';
+
+/** @see https://wicg.github.io/serial/#serialoptions-dictionary */
+interface SerialOptions {
+  baudrate: number;
+  databits?: number;
+  stopbits?: number;
+  parity?: ParityType;
+  buffersize?: number;
+  rtscts?: boolean;
+}
+
+/** @see https://wicg.github.io/serial/#serialport-interface */
+declare class SerialPort {
+  readonly readable: ReadableStream<Uint8Array>;
+  readonly writable: WritableStream<Uint8Array>;
+
+  open(options?: SerialOptions): Promise<void>;
+  close(): void;
+}
+
+/** @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_port_filter.idl */
+interface SerialPortFilter {
+  usbVendorId?: number;
+  usbProductId?: number;
+}
+
+/** @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_port_request_options.idl */
+interface SerialPortRequestOptions {
+  filters?: SerialPortFilter[];
+}
+
+/** @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_connection_event_init.idl */
+interface SerialConnectionEventInit extends EventInit {
+  port: SerialPort;
+}
+
+/** @see https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/serial/serial_connection_event.idl */
+declare class SerialConnectionEvent extends Event {
+  constructor(type: string, eventInitDict: SerialConnectionEventInit);
+  readonly port: SerialPort;
+}
+
+/** @see https://wicg.github.io/serial/#serial-interface */
+declare class Serial extends EventTarget {
+  onconnect(): ((this: this, ev: SerialConnectionEvent) => any) | null;
+  ondisconnect(): ((this: this, ev: SerialConnectionEvent) => any) | null;
+  getPorts(): Promise<SerialPort[]>;
+  requestPort(options?: SerialPortRequestOptions): Promise<SerialPort>;
+  addEventListener(
+      type: 'connect' | 'disconnect',
+      listener: (this: this, ev: SerialConnectionEvent) => any,
+      useCapture?: boolean): void;
+  addEventListener(
+      type: string,
+      listener: EventListenerOrEventListenerObject | null,
+      options?: boolean | AddEventListenerOptions): void;
+  removeEventListener(
+      type: 'connect' | 'disconnect',
+      callback: (this: this, ev: SerialConnectionEvent) => any,
+      useCapture?: boolean): void;
+  removeEventListener(
+      type: string,
+      callback: EventListenerOrEventListenerObject | null,
+      options?: EventListenerOptions | boolean): void;
+}
+
+/** @see https://wicg.github.io/serial/#extensions-to-the-navigator-interface */
+interface Navigator {
+  readonly serial: Serial;
+}
+
+/** @see https://wicg.github.io/serial/#extensions-to-workernavigator-interface */
+interface WorkerNavigator {
+  readonly serial: Serial;
+}