Skip to content

Instantly share code, notes, and snippets.

@imkrish
Created April 20, 2019 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkrish/9e55b6954fc2290847c72a6513d171d9 to your computer and use it in GitHub Desktop.
Save imkrish/9e55b6954fc2290847c72a6513d171d9 to your computer and use it in GitHub Desktop.
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