To explicitly specify the type argument for type-checking purposes, you can do the following:
const a1 = new A<[number]>(2); // this is okay
const a2 = new A<[number]>('Oops'); // this will result in an error
It seems that automatically inferring the type in this manner may not be possible. However, if you are only concerned with the first value in the array (as shown in your example), you could achieve something like this:
class A<U, T extends [U, ...any[]]> {
constructor(public a: U) { }
}
const a = new A(2); // results in type A<number, [number, ...any[]]>
Alternatively, if you prefer to stick with your original definition, you can use a static factory method:
class A<T extends any[]> {
constructor(public a: T[0]) {
}
static create<U>(a: U): A<[U]> {
return new A(a);
}
}
const a = A.create(2); // results in type A<[number]>