github / webauthn-json

🔏 A small WebAuthn API wrapper that translates to/from pure JSON using base64url.
https://github.github.com/webauthn-json/demo/
MIT License
760 stars 61 forks source link

Typescript 4.9.4: Types of property 'authenticatorAttachment' are incompatible #73

Closed uwolfer closed 1 year ago

uwolfer commented 1 year ago

With Typescript 4.9.4, I am getting the following error. With TS 4.8.4, no such error is thrown.

node_modules/@github/webauthn-json/dist/types/basic/json.d.ts:9:18 - error TS2430: Interface 'PublicKeyCredentialWithClientExtensionResults' incorrectly extends interface 'PublicKeyCredential'.
  Types of property 'authenticatorAttachment' are incompatible.
    Type 'string | null | undefined' is not assignable to type 'string | null'.
      Type 'undefined' is not assignable to type 'string | null'.
lgarron commented 1 year ago

Thanks for the report! Unfortunately, this is a recurring problem with a living spec and multiple browser implementations.

In particular, it seems that the field is required (but nullable) in the spec but authenticatorAttachment is not available in Firefox 109 (or as of Firefox 111.0a1 nightly) on macOS, and I can't even find a bug for it: https://bugzilla.mozilla.org/buglist.cgi?quicksearch=authenticatorAttachment

Some options:

  1. Make PublicKeyCredentialWithClientExtensionResults extend Omit<PublicKeyCredential, "authenticatorAttachment"> instead of PublicKeyCredential.
  2. Publish a package with types that are incompatible with Firefox.
  3. Try to convince TypeScript to mark the field as optional for now.
  4. Get Firefox to add support.

Option 2 is probably the least surprising, but it makes me very cranky about the health of the web platform.

lgarron commented 1 year ago

I've submitted a Firefox bug at https://bugzilla.mozilla.org/show_bug.cgi?id=1810851

lgarron commented 1 year ago
  1. Make PublicKeyCredentialWithClientExtensionResults extend Omit<PublicKeyCredential, "authenticatorAttachment"> instead of PublicKeyCredential.

I'm going to go with this option, because this is consistent with the schema, and I can't change the schema without changing Firefox:

https://github.com/github/webauthn-json/blob/80ffb1c7de3bd2fb02a7834fd65c670036f21d1d/src/webauthn-json/basic/schema.ts#L59