-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
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.
interface SquareConfig {
color?: string;
width?: number;
}
function createSquare(config: SquareConfig): {color: string; area: number} {
var newSquare = {color: "white", area: 100};
if (config.color) {
newSquare.color = config.color;
}
if (config.width) {
newSquare.area = config.width * config.width;
}
return newSquare;
}
two way call function and to reply
1.
var obj = {color1: "black"};
var mySquare = createSquare(obj);
is correct work
but
2.
var mySquare = 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'.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created