Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Commit 8c8af29

Browse files
committed
Update examples to TypeScript.
It seems to be impossible to write straightforward code with JSDoc annotations that is correctly typed in both JS and TS files, because the `@type` annotations are not correctly applied to the dynamic import. So we just provide a straight-up TypeScript example, and folks can remove the types if they are using JS.
1 parent dea67c7 commit 8c8af29

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@ By design, these are compatible with `@github/webauthn-json` encoding, so you ca
1414

1515
If you need to support older browsers in the short-term, consider loading this library only as a fallback:
1616

17-
```js
17+
```ts
18+
// Example in TypeScript
19+
1820
async function register() {
1921
const parseCreationOptionsFromJSON =
2022
PublicKeyCredential.parseCreationOptionsFromJSON ??
21-
/* @type PublicKeyCredential.parseCreationOptionsFromJSON */
22-
(await import("@github/webauthn-json/browser-ponyfill")).parseCreationOptionsFromJSON;
23+
((await import("@github/webauthn-json/browser-ponyfill"))
24+
.parseCreationOptionsFromJSON as unknown as typeof PublicKeyCredential.parseCreationOptionsFromJSON);
2325

2426
const publicKey = parseCreationOptionsFromJSON({ /**/ });
25-
return navigator.credentials.create({publicKey});
27+
const credential = (await navigator.credentials.create({publicKey})) as PublicKeyCredential;
28+
return credential.toJSON();
2629
}
2730

2831
async function authenticate() {
2932
const parseRequestOptionsFromJSON =
3033
PublicKeyCredential.parseRequestOptionsFromJSON ??
31-
/* @type PublicKeyCredential.parseRequestOptionsFromJSON */
32-
(await import("@github/webauthn-json/browser-ponyfill")).parseRequestOptionsFromJSON;
34+
((await import("@github/webauthn-json/browser-ponyfill"))
35+
.parseRequestOptionsFromJSON as unknown as typeof PublicKeyCredential.parseRequestOptionsFromJSON);
3336

3437
const publicKey = parseRequestOptionsFromJSON({ /**/ });
35-
return navigator.credentials.get({publicKey});
38+
const credential = (await navigator.credentials.get({publicKey})) as PublicKeyCredential;
39+
return credential.toJSON();
3640
}
3741
```
3842

0 commit comments

Comments
 (0)