panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

Dynamic Registration Typescript Error #255

Closed jwheeler-gs closed 4 years ago

jwheeler-gs commented 4 years ago

There seems to be a type definition problem with TypeOfGenericClient<Client>. The register method is declared as static and cannot be accessed from a Client instance according to the TS definition. Given the code below:

import { Issuer } from 'openid-client';
const issuer = new Issuer({
          issuer: 'http://example.com',
          registration_endpoint: 'https://op.example.com/client/registration',
        });
const client = await issuer.Client.register(this.metadata);

I am getting this error:

Property 'register' does not exist on type 'TypeOfGenericClient<Client>'. ts(2339)

I'm using the code the same way as the javascript example in this repo's tests folder. I'm not sure if I need to do something differently for Typescript or not. Is there an example somewhere of how to do dynamic registration differently for typescript usage of this library? It looks like in TS land the register method is static instead of being an instance member?

static register(metadata: object, other?: RegisterOther & ClientOptions): Promise<Client>;
jwheeler-gs commented 4 years ago

As a very hacky workaround to be able to compile right now, I'm currently doing the following:

interface MyClient extends TypeOfGenericClient<Client> {
  register: typeof Client.register;
}

client = await (issuer.Client as MyClient).register(this.metadata);
panva commented 4 years ago

Yeah i’ll see to get it fixed. Thanks for raising this

panva commented 4 years ago

Actually, this is a duplicate of #232, i welcome anyone with the TS skills to add this to the list of things to fix