Complete the code to declare a generic Builder class.
class Builder<[1]> { private value: T; constructor(initialValue: T) { this.value = initialValue; } }
The generic type parameter T is used to define the type for the Builder class.
Complete the method to set a new value in the Builder class.
setValue(newValue: T): this {
this.value = [1];
return this;
}value instead of newValue.this.value to itself.The method should assign the parameter newValue to the internal value property.
Fix the error in the build method to return the stored value.
build(): [1] { return this.value; }
void which means no return value.number which may not match T.The build method should return the generic type T which is the type of the stored value.
Fill both blanks to create a generic Builder method that updates a property and returns the builder.
setProperty<K extends keyof T>(key: [1], value: T[K]): this { this.value[key] = [2]; return this; }
key as the type instead of the parameter name.key instead of value to the property.The method uses K as the key type and assigns value to the property.
Fill all three blanks to create a generic Builder class with a static create method.
class Builder<[1]> { private value: T; private constructor(initialValue: T) { this.value = initialValue; } static create<[2]>(initialValue: [3]): Builder<U> { return new Builder<U>(initialValue); } }
The class uses T as the generic type. The static method defines its own generic U and uses it for the parameter and return type.