Skip to content

Fail to check Enum in Record #123

@thekingofcity

Description

@thekingofcity

data is not a valid Translation in the following code because kr should be ko, but is<Translation>(data) === true. Let me know if it is not supported yet.

import { is } from 'typescript-is';

enum LanguageCode {
    Arabic = 'ar',
    ChineseSimp = 'zh-Hans',
    ChineseTrad = 'zh-Hant',
    English = 'en',
    French = 'fr',
    German = 'de',
    Japanese = 'ja',
    Korean = 'ko', // <-- this line
    Portuguese = 'pt',
    Russian = 'ru',
}

type Translation = { [l in LanguageCode]?: string };

const data = {
    en: 'Line 1',
    kr: '1호선 ', // <-- this line
    'zh-Hans': '1号线',
    'zh-Hant': '1號線',
};

console.log(is<Translation>(data));

I ran it under ttypescript and ts-node by $Env:TS_NODE_COMPILER="ttypescript" and then node --loader ts-node/esm test.ts. typescript-is === 0.19.0 ttypescript === 1.5.13 typescript === 4.5.4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions