Skip to content

refactor: stronger typing of inputs #473

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

Merged
merged 11 commits into from
Aug 3, 2024
Prev Previous commit
Next Next commit
fixup! refactor: stronger typing of inputs
  • Loading branch information
andreialecu committed Jul 29, 2024
commit d76736316307d7e059cf3431c96a10f2eea4a1a4
4 changes: 1 addition & 3 deletions projects/testing-library/src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ export type AliasedInputs = Record<string, AliasedInput<unknown>>;

export type ComponentInput<T> =
| {
[P in keyof T]?: T[P] extends Signal<infer U>
? U // If the property is a Signal, apply Partial to the inner type
: Partial<T[P]>; // Otherwise, apply Partial to the property itself
[P in keyof T]?: T[P] extends Signal<infer U> ? U : T[P];
}
| AliasedInputs;

Expand Down
32 changes: 20 additions & 12 deletions projects/testing-library/tests/render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,29 @@ describe('inputs and signals', () => {
});

it('should typecheck correctly', async () => {
// @ts-expect-error - myName is a string
await render(InputComponent, {
inputs: {
myName: 123,
// we only want to check the types here
// so we are purposely not calling render

const typeTests = [
() => {
// @ts-expect-error - myName is a string
await render(InputComponent, {
inputs: {
myName: 123,
},
});
},
});

// @ts-expect-error - job is not using aliasedInputWithValue
await render(InputComponent, {
inputs: {
job: 'not used with aliasedInputWithValue',
() => {
// @ts-expect-error - job is not using aliasedInputWithValue
await render(InputComponent, {
inputs: {
job: 'not used with aliasedInputWithValue',
},
});
},
});
];

// add a statement so the test succeeds
expect(true).toBeTruthy();
expect(typeTests).toBeTruthy();
});
});