TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

`.toJSON()` on `PublicKeyCredential` effectively returns `any`

Open lgarron opened this issue 6 months ago • 0 comments

Consider the following code:

async function register() {
  const publicKey = PublicKeyCredential.parseCreationOptionsFromJSON({ /* … */ });
  const credential = (await navigator.credentials.create({publicKey})) as PublicKeyCredential;
  return credential.toJSON();
}

The type of the returned code is any because:

  • .toJSON() returns PublicKeyCredentialJSON and
  • PublicKeyCredentialJSON is defined as any.

This is fine for some use cases, but it completely removes type safety for accessing any fields on the returned value.

@github/webauthn-json is winding down, and developers who transition to the built-in functions will gain some benefits at the expense of losing these types.

I'd be happy to contribute full types for these, since the actual types can be ported and adapted from @github/webauthn-json somewhat directly. However, I'm not clear on how to integrate this into TypeScript-DOM-lib-generator, as it would be a lot to add to overridingTypes.jsonc.

lgarron avatar Aug 08 '25 22:08 lgarron