aurelia / template-lint

Sanity check of Aurelia-flavor template HTML
Apache License 2.0
56 stars 17 forks source link

Support typeof operator #153

Open zakjan opened 7 years ago

zakjan commented 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.