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

Isolated declarations errors occur in third-party node_modules when they ship with original TypeScript source files #58909

Closed
MichaelMitchell-at opened this issue Jun 18, 2024 · 3 comments Β· Fixed by #59203
Assignees
Labels
Bug A bug in TypeScript Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag Fix Available A PR has been opened for this issue

Comments

@MichaelMitchell-at
Copy link

MichaelMitchell-at commented Jun 18, 2024

πŸ”Ž Search Terms

isolated declarations node_modules

πŸ•— Version & Regression Information

  • Currently reproduces in nightly

⏯ Playground Link

No response

πŸ’» Code

// @filename: package.json
{
  "dependencies": {
    "@trpc/server": "10.29.1",
    "typescript": "5.6.0-dev.20240617"
  }
}

// @filename: tsconfig.json
{
  "compilerOptions": {
    "declaration": true,
    "emitDeclarationOnly": true,
    "isolatedDeclarations": true,
    "outDir": "declarations",
    "skipLibCheck": true
  },
  "files": ["index.ts"],
  "include": ["index.ts"]
}

// @filename: index.ts
import { initTRPC } from "@trpc/server";

const trpc = initTRPC.create();

export const middleware = trpc.middleware;
export const router = trpc.router;
export const publicProcedure = trpc.procedure;

πŸ™ Actual behavior

Error:

index.ts:5:14 - error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.

5 export const middleware = trpc.middleware;
               ~~~~~~~~~~

  index.ts:5:14
    5 export const middleware = trpc.middleware;
                   ~~~~~~~~~~
    Add a type annotation to the variable middleware.

index.ts:6:14 - error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.

6 export const router = trpc.router;
               ~~~~~~

  index.ts:6:14
    6 export const router = trpc.router;
                   ~~~~~~
    Add a type annotation to the variable router.

index.ts:7:14 - error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.

7 export const publicProcedure = trpc.procedure;
               ~~~~~~~~~~~~~~~

  index.ts:7:14
    7 export const publicProcedure = trpc.procedure;
                   ~~~~~~~~~~~~~~~
    Add a type annotation to the variable publicProcedure.

node_modules/@trpc/server/dist/core/initTRPC.d.ts:72:22 - error TS9039: Type containing private name 'RootConfig' can't be used with --isolatedDeclarations.

72             _config: RootConfig<{
                        ~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:75:29 - error TS9039: Type containing private name 'ErrorFormatterShape' can't be used with --isolatedDeclarations.

75                 errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                               ~~~~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:75:49 - error TS9039: Type containing private name 'PickFirstDefined' can't be used with --isolatedDeclarations.

75                 errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                                                   ~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:75:94 - error TS9039: Type containing private name 'ErrorFormatter' can't be used with --isolatedDeclarations.

75                 errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                                                                                                ~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:75:166 - error TS9039: Type containing private name 'DefaultErrorShape' can't be used with --isolatedDeclarations.

75                 errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                                                                                                                                                                        ~~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:76:62 - error TS9039: Type containing private name 'DataTransformerOptions' can't be used with --isolatedDeclarations.

76                 transformer: TOptions["transformer"] extends DataTransformerOptions ? TOptions["transformer"] : DefaultDataTransformer;
                                                                ~~~~~~~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:76:113 - error TS9039: Type containing private name 'DefaultDataTransformer' can't be used with --isolatedDeclarations.

76                 transformer: TOptions["transformer"] extends DataTransformerOptions ? TOptions["transformer"] : DefaultDataTransformer;
                                                                                                                   ~~~~~~~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:88:157 - error TS9039: Type containing private name 'RootConfig' can't be used with --isolatedDeclarations.

88         router: <TProcRouterRecord extends import("./router").ProcedureRouterRecord>(procedures: TProcRouterRecord) => import("./router").CreateRouterInner<RootConfig<{
                                                                                                                                                               ~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:91:25 - error TS9039: Type containing private name 'ErrorFormatterShape' can't be used with --isolatedDeclarations.

91             errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                           ~~~~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:91:45 - error TS9039: Type containing private name 'PickFirstDefined' can't be used with --isolatedDeclarations.

91             errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                                               ~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:91:90 - error TS9039: Type containing private name 'ErrorFormatter' can't be used with --isolatedDeclarations.

91             errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                                                                                            ~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:91:162 - error TS9039: Type containing private name 'DefaultErrorShape' can't be used with --isolatedDeclarations.

91             errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
                                                                                                                                                                    ~~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:92:58 - error TS9039: Type containing private name 'DataTransformerOptions' can't be used with --isolatedDeclarations.

92             transformer: TOptions["transformer"] extends DataTransformerOptions ? TOptions["transformer"] : DefaultDataTransformer;
                                                            ~~~~~~~~~~~~~~~~~~~~~~

node_modules/@trpc/server/dist/core/initTRPC.d.ts:92:109 - error TS9039: Type containing private name 'DefaultDataTransformer' can't be used with --isolatedDeclarations.

92             transformer: TOptions["transformer"] extends DataTransformerOptions ? TOptions["transformer"] : DefaultDataTransformer;
                                                                                                               ~~~~~~~~~~~~~~~~~~~~~~


Found 17 errors in 2 files.

Errors  Files
     3  index.ts:5
    14  node_modules/@trpc/server/dist/core/initTRPC.d.ts:72

πŸ™‚ Expected behavior

Type errors only occur in index.ts

Additional information about the issue

@trpc/server is packaged with the original source files, e.g. node_modules/@trpc/server/src/core/initTRPC.ts, rather than declaration files.

@MichaelMitchell-at
Copy link
Author

This also seems to lead to a crash when using the typescript API service.getCombinedCodeFix to apply the fixMissingTypeAnnotationOnExports fix.

Type Error: Cannot read properties of undefined (reading 'flags')
    at needsNameFromDeclaration (node_modules/typescript/lib/typescript.js:138367:19)
    at getNameForExportedSymbol (node_modules/typescript/lib/typescript.js:138361:7)
    at visit (node_modules/typescript/lib/typescript.js:161633:20)
    at visitNode (node_modules/typescript/lib/typescript.js:92641:19)
    at visitEachChildOfPropertySignature (node_modules/typescript/lib/typescript.js:92939:7)
    at visitEachChild (node_modules/typescript/lib/typescript.js:92889:33)
    at visit (node_modules/typescript/lib/typescript.js:161639:12)
    at visitArrayWorker (node_modules/typescript/lib/typescript.js:92703:49)
    at visitNodes2 (node_modules/typescript/lib/typescript.js:92674:19)
    at visitEachChildOfTypeLiteralNode (node_modules/typescript/lib/typescript.js:93079:7)

@MichaelMitchell-at
Copy link
Author

Actually the fact that trpc ships with the original TypeScript source might be a red herring. It might be something else at play.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 18, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.6.0 milestone Jun 18, 2024
@weswigham weswigham added the Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag label Jun 20, 2024
@weswigham
Copy link
Member

weswigham commented Jun 20, 2024

Yeah, this is only a hunch, since I'm still debugging the issue, but I suspect we're just not filtering calls to reportInferenceFallback to only nodes we're trying to copy form the active file - so we're trying to copy nodes from the target of the alias (which is in the target declaration file) and reporting bogus errors. The attempt to copy and subsequent non-copying fallback are both fine - a top-level error was already emitted on the actual input declaration, so we're just over-erroring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants