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

Feat start with types #986

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 7 additions & 1 deletion library/src/actions/endsWith/endsWith.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ describe('endsWith', () => {

describe('should infer correct types', () => {
type Action = EndsWithAction<string, 'foo', undefined>;
type Action2 = EndsWithAction<InferOutput<Action>, 'bar', undefined>;


test('of input', () => {
expectTypeOf<InferInput<Action>>().toEqualTypeOf<string>();
});

test('of output', () => {
expectTypeOf<InferOutput<Action>>().toEqualTypeOf<string>();
expectTypeOf<InferOutput<Action>>().toEqualTypeOf<`${string}foo`>();
});

test('of output after pipe', () => {
expectTypeOf<InferOutput<Action2>>().toEqualTypeOf<`${string}bar`>();
});

test('of issue', () => {
Expand Down
2 changes: 1 addition & 1 deletion library/src/actions/endsWith/endsWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface EndsWithAction<
TMessage extends
| ErrorMessage<EndsWithIssue<TInput, TRequirement>>
| undefined,
> extends BaseValidation<TInput, TInput, EndsWithIssue<TInput, TRequirement>> {
> extends BaseValidation<TInput, `${string}${TRequirement}`, EndsWithIssue<TInput, TRequirement>> {
/**
* The action type.
*/
Expand Down
10 changes: 8 additions & 2 deletions library/src/actions/startsWith/startsWith.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
startsWith,
type StartsWithAction,
type StartsWithIssue,
} from './startsWith.ts';
} from './startsWith.ts';

describe('startsWith', () => {
describe('should return action object', () => {
Expand All @@ -31,13 +31,18 @@ describe('startsWith', () => {

describe('should infer correct types', () => {
type Action = StartsWithAction<string, 'foo', undefined>;
type Action2 = StartsWithAction<InferOutput<Action>, 'bar', undefined>;

test('of input', () => {
expectTypeOf<InferInput<Action>>().toEqualTypeOf<string>();
});

test('of output', () => {
expectTypeOf<InferOutput<Action>>().toEqualTypeOf<string>();
expectTypeOf<InferOutput<Action>>().toEqualTypeOf<`foo${string}`>();
});

test('of output after pipe', () => {
expectTypeOf<InferOutput<Action2>>().toEqualTypeOf<`bar${string}`>();
});

test('of issue', () => {
Expand All @@ -47,3 +52,4 @@ describe('startsWith', () => {
});
});
});

2 changes: 1 addition & 1 deletion library/src/actions/startsWith/startsWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface StartsWithAction<
| undefined,
> extends BaseValidation<
TInput,
TInput,
`${TRequirement}${string}`,
StartsWithIssue<TInput, TRequirement>
> {
/**
Expand Down