Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
interface User {
readonly id: number;
readonly name: string;
readonly wifeName: string;
readonly parents: ReadonlyArray<string>;
}
const user: User = {
id: 1,
name: "John",
wifeName: "Mary",
parents: ["George", "Maria"]
};
user = {}; // Cannot assign to 'user' because it is a constant.
user.id = 2; // Cannot assign to 'id' because it is a read-only property.
user.wifeName = 'Hermione'; // Cannot assign to 'wifeName' because it is a read-only property.
user.parents = []; // Cannot assign to 'parents' because it is a read-only property.
user.parents.push("Thor"); // Property 'push' does not exist on type 'readonly string[]'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.