use of const enum may produce unexpected results
Closed this issue · 2 comments
bennypowers commented
Shavua tov.
The flags
dict is defined as a typescript const enum
. This can lead to difficulties:
Input:
import { flags } from '@hebcal/core';
const f = Object.fromEntries(Object.entries(
// @ts-expect-error: whatever
flags
));
console.log(f);
console.log(flags.CHAG)
Output:
const f = Object.fromEntries(Object.entries(
// @ts-expect-error: whatever
flags));
console.log(f);
console.log(0 /* flags.CHAG */);
export {};
The correct flag for CHAG
is 1
. Code relying on flags.CHAG and thus-compiled will fail. I worked around this by copying the flags table into my code. A better solution would be to export the table as an object
export const flags = {
// ...
} as const;
An even better solution would be to vend predicates instead of bitmasks.
Besoros tovos
mjradwin commented
Thanks for the bug report! We're sorry about TypeScript errors. Can you try 4.5.1 and let us know if this fixes the problem for you?
bennypowers commented
dd5b87f seems to fix it
if you adopt ts sources, let me suggest using export const flags = {/*..*/} as const
instead, which is more flexible