по-динамически получаемоему ключу, всё выглядит примерно так 
                  
                  
                  export class NewClass {
                  
                  
                    public value1: string;
                  
                  
                    public value2: boolean;
                  
                  
                  
                  
                  
                    constructor(params?: Partial<ButtonConfig>) {
                  
                  
                      Object.assign(this, params);
                  
                  
                    }
                  
                  
                  
                  
                  
                    public setValueByProp(prop: keyof NewClass, value: string | boolean): void {
                  
                  
                      this[prop] = value;
                  
                  
                    }
                  
                  
                  }
                  
                  
                  
                  
                  
                  ругается на this[prop] и пишет
                  
                  
                  Type '' is not assignable to type 'never'.
                  
                  
                    Type 'string' is not assignable to type 'never'
                  
                  
                  как это переделать?
                  
                  
                
попробуйте так: public setValueByProp<K extends keyof NewClass>(prop: K, value: NewClass[K]): void { this[prop] = value; }
прилетело вот такое счастье Type 'NewClass[K]' is not assignable to type 'this[K]'. Type 'NewClass' is not assignable to type 'this'. 'NewClass' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'NewClass'. Type 'NewClass[K]' is not assignable to type 'never'. Type 'string | boolean | (<K extends "setValueByProp" | "value1" | "value2">(prop: K, value: NewClass[K]) => void)' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'.
а если добавить в начале метода this: NewClass?
не совсем понял как его пропикывать, так?
public setValueByProp<…>(this: NewClass, …
хм... ругаться перестало, надо потестить
класс, работает, спасибо... осталось понять физику процесса
Обсуждают сегодня