type TestType<A> = [A] extends [never] ? void : A
class Singleton<T, A> {
private ClassRef: (new (...args: A[]) => T)
private args: TestType<A>
private _instance?: T
constructor(ClassRef: (new (...args: A[]) => T), args: TestType<A>) {
this.ClassRef = ClassRef
this.args = args
}
public get instance() {
if (!this._instance) {
this._instance = new this.ClassRef(this.args as A)
}
return this._instance
}
}
class Empty {}
const test = new Singleton(Empty)
If I specify
type TestType<A> = void
The compiler does not show any errors. However, when I do it conditionally, I encounter an error saying "Expected 2 arguments, but got 1."