inngest / inngest-js

The developer platform for easily building reliable workflows with zero infrastructure for TypeScript & JavaScript
https://www.inngest.com/
GNU General Public License v3.0
414 stars 41 forks source link

[BUG] The inferred type cannot be named without a reference to '../node_modules/inngest/components/InngestFunction' when using `composite` #384

Closed MonsterDeveloper closed 11 months ago

MonsterDeveloper commented 11 months ago

Describe the bug When enabling the composite in a project's tsconfig.json, the compiler shows an error when using inngest.createFunction:

The inferred type of 'default' cannot be named without a reference to '../node_modules/inngest/components/InngestFunction'. This is likely not portable. A type annotation is necessary. typescript(2742)

To Reproduce Steps to reproduce the behavior:

  1. Create a function with inngest.createFunction
  2. Enable composite in tsconfig.json

Link to reproduction: CodeSandbox

Expected behavior Inngest library should be working within composite projects without errors.

Code snippets / Logs / Screenshots CleanShot 2023-11-07 at 13 53 39@2x

System info (please complete the following information):

jpwilliams commented 11 months ago

Are yu using pnpm, @MonsterDeveloper? This might be related to microsoft/TypeScript#47663.

MonsterDeveloper commented 11 months ago

On my local machine yes, but I was able to reproduce the bug in CodeSandbox that uses yarn as well. Furthermore, Inngest is the only library in my project giving that error in composite mode, which makes me think it’s not an issue with the compiler.

Although I don’t know what is it caused by and can’t think of a possible fix. On 7. Nov 2023 at 16:40 +0100, Jack Williams @.***>, wrote:

Are yu using pnpm, @MonsterDeveloper? This might be related to microsoft/TypeScript#47663. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

MonsterDeveloper commented 11 months ago

@jpwilliams after a bit of research, it seems to me that it is indeed an issue with the TypeScript compiler. I found a temporary fix — importing the types from the error directly:

import { InngestFunction } from "../node_modules/inngest/components/InngestFunction";
import type * as InngestTypes from "../node_modules/inngest/types";

// no errors now
export default inngest.createFunction(
  { id: "send-welcome-email" },
  { event: "user/new.signup" },
  async () => {
    return "some action";
  },
);

CodeSandbox link

But because inngest package doesn't export the types from types folder and components/InngestFunction, they have to be imported through a nasty node_modules direct import.

Since we can't fix tsc here, it'd be nice to include these exports so a better workaround can be used.

jpwilliams commented 11 months ago

Released in kbd>[inngest@3.4.3](https://github.com/inngest/inngest-js/releases/tag/inngest%403.4.3)</kbd.

Thanks for the thorough investigation and workaound, @MonsterDeveloper. 🙌