Coggle requires JavaScript to display documents.
type User = { name: string; age: number; }
interface User { name: string; age: number; }
interface PointOptions { shape: Shape; xPos?: number; yPos?: number; }
interface SomeType { readonly prop: string; } function doSomething(obj: SomeType) { // We can read from 'obj.prop'. console.log(`prop has the value '${obj.prop}'.`); // But we can't re-assign it. obj.prop = "hello"; }
Cannot assign to 'prop' because it is a read-only property.
interface Person { readonly id: number; first: string; last: string; nickname?: string; sayHi: () => string; }
sayHi
const thomas: Person = { first: "Thomas", last: "Hardy", nickname: "Tom", id: 21837, sayHi: () => { return "Hello!"; }, };
interface Person { . . . sayHi(): string; }
interface Product { name: string; price: number; applyDiscount(discount: number): number; }
interface Dog { name: string; age: number; } ... some time later, add... interface Dog { breed: string; bark(): string; } const elton: Dog = { name: "Elton", age: 0.5, breed: "Australian Shepherd", bark() { return "WOOF WOOF!"; }, };