Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

My typescript validation is different.

At around 11mins, you added another key/value pairing to the object being passed through the sendEmail function. When you added this pairing ("phone" = "07559329382"), your IDE was satisfied that it's valid. However, my IDE says "Object literal may only specify known properties".

So, is adding a new pairing that does not exist in the Interface considered as invalid typescript? Or can you add properties that do not exist in the interface. I'm only confused as your one did not bring this error up.

My code is as follows:

interface IEmailable { name: string, email: string }

function sendEmail(contact: IEmailable){ console.log(contact.name + " <" + contact.email + ">"); }

sendEmail({ name: "Ciaran", email: "ciaran.w@touchcreative.co.uk", // error here, 'phone' doesn't exist in interface IEmailable phone: "ssss" });]

Video here: https://teamtreehouse.com/library/getting-started-with-typescript

1 Answer

Steven Parker
Steven Parker
243,318 Points

Interesting! The TypeScript Playground shows the same error, however it does generate code that includes and effectively uses the extra property.

But you may still want to report this as a possible bug to the staff as described on the Support page.

Thanks for answering! I think it may have been valid typescript in an older version. I've searched the TypeScript docs however and can't find anything insinuating this :(