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

fix(store): rename template literal to string literal for createActionGroup #3426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/store/spec/types/action_group_creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ describe('createActionGroup', () => {
});

describe('source', () => {
it('should fail when source is not a template literal type', () => {
it('should fail when source is not a string literal type', () => {
expectSnippet(`
const booksApiActions = createActionGroup({
source: 'Books API' as string,
events: {},
});
`).toFail(/source must be a template literal type/);
`).toFail(/source must be a string literal type/);
});
});

Expand Down Expand Up @@ -116,15 +116,15 @@ describe('createActionGroup', () => {
);
});

it('should fail when event name is not a template literal type', () => {
it('should fail when event name is not a string literal type', () => {
expectSnippet(`
const booksApiActions = createActionGroup({
source: 'Books API',
events: {
['Load Books Success' as string]: emptyProps()
},
});
`).toFail(/event name must be a template literal type/);
`).toFail(/event name must be a string literal type/);
});

describe('forbidden characters', () => {
Expand Down
8 changes: 4 additions & 4 deletions modules/store/src/action_group_creator_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ type EmptyStringCheck<
? `${Name} cannot be an empty string or contain only spaces`
: unknown;

type TemplateLiteralCheck<
type StringLiteralCheck<
Str extends string,
Name extends string
> = string extends Str ? `${Name} must be a template literal type` : unknown;
> = string extends Str ? `${Name} must be a string literal type` : unknown;

type UniqueEventNameCheck<
EventNames extends string,
Expand Down Expand Up @@ -120,11 +120,11 @@ export interface ActionGroupConfig<
Source extends string,
Events extends Record<string, ActionCreatorProps<unknown> | Creator>
> {
source: Source & TemplateLiteralCheck<Source, 'source'>;
source: Source & StringLiteralCheck<Source, 'source'>;
events: {
[EventName in keyof Events]: Events[EventName] &
EmptyStringCheck<EventName & string, 'event name'> &
TemplateLiteralCheck<EventName & string, 'event name'> &
StringLiteralCheck<EventName & string, 'event name'> &
ForbiddenCharactersCheck<EventName & string, 'event name'> &
UniqueEventNameCheck<keyof Events & string, EventName & string> &
NotAllowedEventPropsCheck<Events[EventName]>;
Expand Down