Both of your examples have the same (perceived) error, which is that you specified a property that SquareConfig is not SquareConfig , which often means that you SquareConfig property name incorrectly.
In your case, you specified color1 , where you probably intended to use color .
This code would compile using older versions of TypeScript until an additional function for checking for undefined properties was added.
embarrassing ...
Option One, specify the correct property:
var mySquare = createSquare({color: "black"});
Option two, you intentionally intend to include some other property, use a type statement to tell the compiler that you know is better than it (as long as you are sure that you really know that you know better than it is!):
var mySquare = createSquare(<SquareConfig>{color1: "black"});
Comment Based Update
The compiler is more strict the less "degrees of separation" you have ... for example:
// Error var obj: SquareConfig = {color1: "black"}; // OK var obj = {color1: "black"}; var obj2: SquareConfig = obj;
Let's look at the first example, we say: "I intend to create SquareConfig ." The compiler says: "Well, there are no required elements, since everything is optional, but you are creating an object with a property that I will not recognize, so I will warn you."
The second example is slightly different. We say: "I intend to use the object that I have as SquareConfig ." The compiler says: "this is the object that you intend to use if you do not have any necessary properties ... and each property has the correct structural matching type for SquareConfig - yes."
If the second scenario warned you about properties that do not exist in the target structure, you would not be able to take advantage of the uber polymorphism offered by the structural type system.