add new property in Typescript object
问题 I'm trying to add new property in object, but typescript given error. error TS2339: Property 'qty' does not exist on type 'Object'. product: Object = {qty: Number}; foo(){ this.product.qty = 1; } 回答1: Object is the wrong annotation. Change your annotation: product: {qty: number} = {qty: 0}; foo(){ this.product.qty = 1; } 回答2: Number is a data type not a value. the object only accept the value not datatype. So you can't declare number as a value try this simple way product: any; foo(){ this