Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support typeof operator #153

Open
zakjan opened this issue Jan 13, 2017 · 0 comments
Open

Support typeof operator #153

zakjan opened this issue Jan 13, 2017 · 0 comments

Comments

@zakjan
Copy link

zakjan commented Jan 13, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants