Open zakjan opened 7 years ago
item.ts
// string enum - see https://github.com/Microsoft/TypeScript/issues/3192 function mkenum<T extends {[index: string]: U}, U extends string>(x: T): T { return x; } type enumType<T> = T[keyof T]; export const ItemType = mkenum({ A: "A", B: "B", }); export type ItemType = enumType<typeof ItemType>; export interface Item { name: string; type: ItemType; } export class ItemViewModel { item: Item; get ItemType(): typeof ItemType { return ItemType; } }
item.html
<template> ${item.name} <template if.bind="item.type === ItemType.A"> Aaa </template> <template if.bind="item.type === ItemType.B"> Bbb </template> <template if.bind="item.type === ItemType.C"> Ccc </template> </template>
typeof ItemType is {A: "A", B: "B"} -> ItemType.C should throw a warning.
typeof ItemType
{A: "A", B: "B"}
ItemType.C
item.ts
item.html
typeof ItemType
is{A: "A", B: "B"}
->ItemType.C
should throw a warning.