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

No implicit any #147

Merged
merged 3 commits into from
Jun 7, 2024
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
4 changes: 3 additions & 1 deletion src/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function toError(maybeError: unknown): Error {
* That function is gonna catch any errors and always return a Result.
* @param fn a function to be used as a Composable
*/
function composable<T extends (...args: any[]) => any>(fn: T): Composable<T> {
function composable<T extends Function>(
fn: T,
): Composable<T extends (...args: any[]) => any ? T : never> {
return async (...args) => {
try {
// deno-lint-ignore no-explicit-any
Expand Down
10 changes: 8 additions & 2 deletions src/tests/constructors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ describe('composable', () => {
assertEquals(res, success(3))
})

it('will enforce noImplicitAny', () => {
// @ts-expect-error: implicit any
const fn = composable((a) => a)
type _FN = Expect<Equal<typeof fn, Composable<(a: any) => any>>>
})

it('infers the types of async functions', async () => {
const fn = composable(asyncAdd)
const res = await fn(1, 2)
Expand Down Expand Up @@ -110,7 +116,7 @@ describe('fromSuccess', () => {
const a = composable(() => 1)

const c = fromSuccess(a)
type _R = Expect<Equal<typeof c, () => Promise<number>>>
type _R = Expect<Equal<typeof c, () => Promise<1>>>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diogob I don't know why it changed.. narrower seems better. Didn't break any other test... any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, but LGTM


assertEquals(await c(), 1)
})
Expand Down Expand Up @@ -145,7 +151,7 @@ describe('withSchema', () => {
assertEquals(await handler(), success('no input!'))
})

it('ignores the input and pass undefined', async () => {
it('defaults non-declared input to unknown', async () => {
const handler = withSchema()((args) => args)
type _R = Expect<
Equal<
Expand Down
Loading