Ravi K Chowdary Ravi K Chowdary - 2 months ago 19
TypeScript Question

Typescript inferred type Error

am in learning process of TypeScript. The below code is throwing errors :


Error:- Unexpected token. A constructor, method, accessor, or property was expected.

[ts] Declaration or statement expected.


class duckType{
public validType(){}
var myVar:any = {id:1, name:"ABC"};

myVar = {id:2};
}
}
var myType = new duckType();
myType.validType();

Answer

Remove the trailing brace }:

public validType() {