Skip to content

Global imports break code in Editor when used via project references #215

@patroza

Description

@patroza

Repro

  1. get repo https://github.com/effect-ts-app/boilerplate

    • checkout branch: repro/global-model-imports
  2. in root of repo:

    • yarn
    • yarn build -w
  3. open root repo in vscode

  4. open an api ts file, set vscode typescript version to workspace version

  5. open api/_src/app.ts, spot error
    Argument of type 'ReqHandler<GetHelloWorldRequest, Has, never, unknown, typeof GetHelloWorldRequest, typeof GetHelloWorldResponse>' is not assignable to parameter of type 'RequestHandler<Has, unknown, unknown, unknown, unknown, unknown, unknown, unknown, SupportedErrors>'.
    Types of property 'Request' are incompatible.
    Type 'typeof GetHelloWorldRequest' is not assignable to type 'Request<unknown, unknown, unknown, unknown, unknown, unknown>'.
    Type 'typeof GetHelloWorldRequest' is missing the following properties from type 'ReqResSchemed<unknown, unknown>': Encoder, Model

  6. open packages/client/_src/HelloWorld/Get.ts
    uncomment: // import { Get, Model } from "@effect-ts-app/schema"
    save

  7. see error disappear in app.ts.

Findings:

  • The issue occurs because the dependency is set as a reference to the project using the dependency.
  • In that case, for VSCode it seems to ignore the d.ts and instead considers the .ts source files instead
  • In such case, if the project has not the same globals loaded that the dependency is using, we get this weird issue.
    in my case though I would prefer not to have to load these globals (they are Schema globals that I use extensively in my model packages, but not in my api for instance)

A workaround; if you remove all the project references from api/tsconfig.json, so that the dist is used even in Editor.
but then of course you will have the editor depend on dist d.ts, instead of source files.

For a moment I thought maybe it helps if the global imports are located in the dependency tsconfig.json "types" section, but alas, no dice :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions