Having a Mixin / Inheritance problem with Typescript - string not assignable to string|number|symbol

27 Views Asked by At

I have a typescript class. I'd like to subclass it and add a mixin. However, it keeps telling me that string not assignable to string|number|symbol. I don't understand why because the method signatures are the same.

type TModel = {
    'User' : {
        username : string,
        password : string  | undefined,
    },
    'APIKey' : {
        privateKey: string,
    }
};
type TProps<T extends keyof TModel> = Partial<TModel[T]>;

type Constructor<T = {}> = new (...args: any[]) => T;

 class VingRecord<T extends keyof TModel> {
    constructor( private props: TProps<T>) { }

    public set<K extends keyof TProps<T>>(_key: K) {}
}

function RoleMixin<T extends Constructor>(Base: T) {
    return class RoleMixin extends Base {  };
}

class UserRecord extends RoleMixin(VingRecord<'User'>) {
    public set<K extends keyof TProps<'User'>>(_key: K) {}
}

Here's a typescript playground link.

The problem goes away if I get rid of the set() method or get rid of the mixin, but I need both of them. I'm at a loss. Anybody have any recommendations?

1

There are 1 best solutions below

1
On

It turns out the reason I was having a problem is due to a bug in Typescript. Here's the bug report I posted: https://github.com/microsoft/TypeScript/issues/52907