diff --git a/src/utils.ts b/src/utils.ts index fa9a65e..0bb12e4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -100,16 +100,18 @@ export function mapAliases( if (schema && typeof schema === 'object') { const { alias } = schema; if (typeof alias === 'string') { + const errorPrefix = `Flag alias ${stringify(alias)} for flag ${stringify(flagName)}`; + if (alias.length === 0) { - throw new Error(`Flag alias for ${stringify(flagName)} cannot be empty`); + throw new Error(`${errorPrefix} cannot be empty`); } if (alias.length > 1) { - throw new Error(`Flag alias for ${stringify(flagName)} must be a single character`); + throw new Error(`${errorPrefix} must be a single character`); } if (aliases.has(alias)) { - throw new Error(`Flag alias ${stringify(alias)} for ${stringify(flagName)} is already used`); + throw new Error(`${errorPrefix} is already used`); } aliases.set(alias, { @@ -204,10 +206,6 @@ export const getFlagType = ( flagName: string, flagSchema: FlagTypeOrSchema, ): TypeFunction => { - if (!flagSchema) { - throw new Error(`Missing type on flag ${stringify(flagName)}`); - } - if (typeof flagSchema === 'function') { return flagSchema; } diff --git a/tests/index.ts b/tests/index.ts index 06b8195..b6967fe 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -94,18 +94,6 @@ describe('Error handling', ({ describe, test }) => { }).toThrow(/* 'Flag collision: Alias "a" is already used' */); }); }); - - test('Missing required type', () => { - expect(() => { - typeFlag({ - // @ts-expect-error missing - missingType: { - alias: 't', - }, - - }, ['--missing-type']); - }).toThrow('Missing type on flag "missingType"'); - }); }); describe('Types', ({ test }) => {