I use typescript version 1.8 (but this problem, there was Previous version and now version)
problem: show error when use difference two way call function.
interfaceSquareConfig{color?: string;width?: number;}functioncreateSquare(config: SquareConfig): {color: string; area: number}{varnewSquare={color: "white",area: 100};if(config.color){newSquare.color=config.color;}if(config.width){newSquare.area=config.width*config.width;}returnnewSquare;}two way call function and to reply
1.
varobj={color1: "black"};varmySquare=createSquare(obj);is correct work
but
2.
varmySquare=createSquare({color1: "black"});above code produce error.
error TS2345: Argument of type '{ color1: string; }' is not assignable to parameter of type 'SquareConfig'.
Object literal may only specify known properties, and 'color1' does not exist in type 'SquareConfig'.
I use typescript version 1.8 (but this problem, there was Previous version and now version)
problem: show error when use difference two way call function.
two way call function and to reply
1.
is correct work
but
2.
above code produce error.