Skip to content

.toJSON() on PublicKeyCredential effectively returns any #2114

@lgarron

Description

@lgarron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions