3 ms·
const someBook: Book = { id: 1, name: "Title", genre: "wstern" // Compile error: [tsserver 2322] [E] Type '"westrn"' is not assignable to
by mssundaram 6y ago
const someBook: Book = {
id: 1,
name: "Title",
genre: "wstern"
// Compile error: [tsserver 2322] [E] Type '"westrn"' is not assignable to type 'Genre'.
};
That's not how string literals work in Typescript. If you mis-type the string you'll get a compile error. It won't make it to runtime.