Skip to content

Commit 859c7d9

Browse files
authored
🤖 Merge PR DefinitelyTyped#74205 [w3c-web-smart-card] Refactor to use global classes and strict DOM maps. by @paulinagacek
1 parent d924629 commit 859c7d9

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

‎types/w3c-web-smart-card/index.d.ts‎

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
* @see https://wicg.github.io/web-smart-card
33
*/
44

5-
export interface SmartCardResourceManager {
6-
establishContext(): Promise<SmartCardContext>;
5+
declare global {
6+
interface SmartCardResourceManager {
7+
establishContext(): Promise<SmartCardContext>;
8+
}
79
}
810

911
export type SmartCardResponseCode =
@@ -28,9 +30,11 @@ export interface SmartCardErrorOptions {
2830
responseCode: SmartCardResponseCode;
2931
}
3032

31-
export class SmartCardError extends DOMException {
32-
constructor(message: string, options: SmartCardErrorOptions);
33-
readonly responseCode: SmartCardResponseCode;
33+
declare global {
34+
class SmartCardError extends DOMException {
35+
constructor(message: string, options: SmartCardErrorOptions);
36+
readonly responseCode: SmartCardResponseCode;
37+
}
3438
}
3539

3640
export interface SmartCardReaderStateIn {
@@ -101,17 +105,19 @@ export interface SmartCardConnectOptions {
101105
preferredProtocols?: SmartCardProtocol[];
102106
}
103107

104-
export interface SmartCardContext {
105-
listReaders(): Promise<string[]>;
106-
getStatusChange(
107-
readerStates: SmartCardReaderStateIn[],
108-
options?: SmartCardGetStatusChangeOptions,
109-
): Promise<SmartCardReaderStateOut[]>;
110-
connect(
111-
readerName: string,
112-
accessMode: SmartCardAccessMode,
113-
options?: SmartCardConnectOptions,
114-
): Promise<SmartCardConnectResult>;
108+
declare global {
109+
interface SmartCardContext {
110+
listReaders(): Promise<string[]>;
111+
getStatusChange(
112+
readerStates: SmartCardReaderStateIn[],
113+
options?: SmartCardGetStatusChangeOptions,
114+
): Promise<SmartCardReaderStateOut[]>;
115+
connect(
116+
readerName: string,
117+
accessMode: SmartCardAccessMode,
118+
options?: SmartCardConnectOptions,
119+
): Promise<SmartCardConnectResult>;
120+
}
115121
}
116122

117123
export type SmartCardConnectionState =
@@ -146,17 +152,19 @@ export interface SmartCardTransmitOptions {
146152

147153
export type SmartCardTransactionCallback = () => Promise<SmartCardDisposition | null>;
148154

149-
export interface SmartCardConnection {
150-
disconnect(disposition?: SmartCardDisposition): Promise<undefined>;
151-
transmit(sendBuffer: BufferSource, options?: SmartCardTransmitOptions): Promise<ArrayBuffer>;
152-
status(): Promise<SmartCardConnectionStatus>;
153-
control(controlCode: number, data: BufferSource): Promise<ArrayBuffer>;
154-
getAttribute(tag: number): Promise<ArrayBuffer>;
155-
setAttribute(tag: number, value: BufferSource): Promise<undefined>;
156-
startTransaction(
157-
transaction: SmartCardTransactionCallback,
158-
options?: SmartCardTransactionOptions,
159-
): Promise<undefined>;
155+
declare global {
156+
interface SmartCardConnection {
157+
disconnect(disposition?: SmartCardDisposition): Promise<void>;
158+
transmit(sendBuffer: BufferSource, options?: SmartCardTransmitOptions): Promise<ArrayBuffer>;
159+
status(): Promise<SmartCardConnectionStatus>;
160+
control(controlCode: number, data: BufferSource): Promise<ArrayBuffer>;
161+
getAttribute(tag: number): Promise<ArrayBuffer>;
162+
setAttribute(tag: number, value: BufferSource): Promise<void>;
163+
startTransaction(
164+
transaction: SmartCardTransactionCallback,
165+
options?: SmartCardTransactionOptions,
166+
): Promise<void>;
167+
}
160168
}
161169

162170
declare global {

‎types/w3c-web-smart-card/w3c-web-smart-card-tests.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import {
22
SmartCardAccessMode,
3-
SmartCardConnection,
43
SmartCardConnectionStatus,
54
SmartCardConnectOptions,
6-
SmartCardContext,
75
SmartCardDisposition,
8-
SmartCardError,
96
SmartCardErrorOptions,
107
SmartCardGetStatusChangeOptions,
118
SmartCardProtocol,
@@ -139,10 +136,10 @@ async function testSmartCardApi() {
139136

140137
const connection: SmartCardConnection = {} as SmartCardConnection;
141138

142-
// $ExpectType Promise<undefined>
139+
// $ExpectType Promise<void>
143140
connection.disconnect("unpower");
144141

145-
// $ExpectType Promise<undefined>
142+
// $ExpectType Promise<void>
146143
connection.disconnect();
147144

148145
const transmitOptions: SmartCardTransmitOptions = {
@@ -161,14 +158,14 @@ async function testSmartCardApi() {
161158
// $ExpectType Promise<ArrayBuffer>
162159
connection.getAttribute(tag);
163160

164-
// $ExpectType Promise<undefined>
161+
// $ExpectType Promise<void>
165162
connection.setAttribute(tag, bufferSource);
166163

167164
const transactionCallback: SmartCardTransactionCallback = async () => "reset";
168165
const transactionOptions: SmartCardTransactionOptions = {
169166
signal: {} as AbortSignal,
170167
};
171168

172-
// $ExpectType Promise<undefined>
169+
// $ExpectType Promise<void>
173170
connection.startTransaction(transactionCallback, transactionOptions);
174171
}

0 commit comments

Comments
 (0)