Skip to content

Commit 326cb1f

Browse files
TypeScript Botweswigham
andauthored
🤖 Pick PR #59203 (Skip ID inference errors on nodes c...) into release-5.5 (#59210)
Co-authored-by: Wesley Wigham <[email protected]>
1 parent 16862b1 commit 326cb1f

6 files changed

+529
-0
lines changed

‎src/compiler/transformers/declarations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export function transformDeclarations(context: TransformationContext) {
303303
}
304304
function reportInferenceFallback(node: Node) {
305305
if (!isolatedDeclarations || isSourceFileJS(currentSourceFile)) return;
306+
if (getSourceFileOfNode(node) !== currentSourceFile) return; // Nested error on a declaration in another file - ignore, will be reemitted if file is in the output file set
306307
if (isVariableDeclaration(node) && resolver.isExpandoFunctionDeclaration(node)) {
307308
reportExpandoFunctionErrors(node);
308309
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
index.ts(5,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
2+
index.ts(6,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
3+
index.ts(7,14): error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
4+
5+
6+
==== node_modules/@trpc/server/internals/config.d.ts (0 errors) ====
7+
export interface RootConfig<T> {
8+
prop: T;
9+
}
10+
==== node_modules/@trpc/server/internals/utils.d.ts (0 errors) ====
11+
export interface ErrorFormatterShape<T={}> {
12+
prop: T;
13+
}
14+
export type PickFirstDefined<TType, TPick> = undefined extends TType
15+
? undefined extends TPick
16+
? never
17+
: TPick
18+
: TType;
19+
export interface ErrorFormatter<T={},U={}> {
20+
prop: [T, U];
21+
}
22+
export interface DefaultErrorShape<T={}> {
23+
prop: T;
24+
}
25+
==== node_modules/@trpc/server/middleware.d.ts (0 errors) ====
26+
export interface MiddlewareFunction<T={},U={}> {
27+
prop: [T, U];
28+
}
29+
export interface MiddlewareBuilder<T={},U={}> {
30+
prop: [T, U];
31+
}
32+
==== node_modules/@trpc/server/index.d.ts (0 errors) ====
33+
import { RootConfig } from './internals/config';
34+
import { ErrorFormatterShape, PickFirstDefined, ErrorFormatter, DefaultErrorShape } from './internals/utils';
35+
declare class TRPCBuilder<TParams> {
36+
create<TOptions extends Record<string, any>>(): {
37+
procedure: {};
38+
middleware: <TNewParams extends Record<string, any>>(fn: import("./middleware").MiddlewareFunction<{
39+
_config: RootConfig<{
40+
errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
41+
}>;
42+
}, TNewParams>) => import("./middleware").MiddlewareBuilder<{
43+
_config: RootConfig<{
44+
errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
45+
}>;
46+
}, TNewParams>;
47+
router: {};
48+
};
49+
}
50+
51+
export declare const initTRPC: TRPCBuilder<object>;
52+
export {};
53+
==== index.ts (3 errors) ====
54+
import { initTRPC } from "@trpc/server";
55+
56+
const trpc = initTRPC.create();
57+
58+
export const middleware = trpc.middleware;
59+
~~~~~~~~~~
60+
!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
61+
!!! related TS9027 index.ts:5:14: Add a type annotation to the variable middleware.
62+
export const router = trpc.router;
63+
~~~~~~
64+
!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
65+
!!! related TS9027 index.ts:6:14: Add a type annotation to the variable router.
66+
export const publicProcedure = trpc.procedure;
67+
~~~~~~~~~~~~~~~
68+
!!! error TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
69+
!!! related TS9027 index.ts:7:14: Add a type annotation to the variable publicProcedure.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//// [tests/cases/compiler/declarationEmitIsolatedDeclarationErrorNotEmittedForNonEmittedFile.ts] ////
2+
3+
//// [config.d.ts]
4+
export interface RootConfig<T> {
5+
prop: T;
6+
}
7+
//// [utils.d.ts]
8+
export interface ErrorFormatterShape<T={}> {
9+
prop: T;
10+
}
11+
export type PickFirstDefined<TType, TPick> = undefined extends TType
12+
? undefined extends TPick
13+
? never
14+
: TPick
15+
: TType;
16+
export interface ErrorFormatter<T={},U={}> {
17+
prop: [T, U];
18+
}
19+
export interface DefaultErrorShape<T={}> {
20+
prop: T;
21+
}
22+
//// [middleware.d.ts]
23+
export interface MiddlewareFunction<T={},U={}> {
24+
prop: [T, U];
25+
}
26+
export interface MiddlewareBuilder<T={},U={}> {
27+
prop: [T, U];
28+
}
29+
//// [index.d.ts]
30+
import { RootConfig } from './internals/config';
31+
import { ErrorFormatterShape, PickFirstDefined, ErrorFormatter, DefaultErrorShape } from './internals/utils';
32+
declare class TRPCBuilder<TParams> {
33+
create<TOptions extends Record<string, any>>(): {
34+
procedure: {};
35+
middleware: <TNewParams extends Record<string, any>>(fn: import("./middleware").MiddlewareFunction<{
36+
_config: RootConfig<{
37+
errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
38+
}>;
39+
}, TNewParams>) => import("./middleware").MiddlewareBuilder<{
40+
_config: RootConfig<{
41+
errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
42+
}>;
43+
}, TNewParams>;
44+
router: {};
45+
};
46+
}
47+
48+
export declare const initTRPC: TRPCBuilder<object>;
49+
export {};
50+
//// [index.ts]
51+
import { initTRPC } from "@trpc/server";
52+
53+
const trpc = initTRPC.create();
54+
55+
export const middleware = trpc.middleware;
56+
export const router = trpc.router;
57+
export const publicProcedure = trpc.procedure;
58+
59+
//// [index.js]
60+
"use strict";
61+
Object.defineProperty(exports, "__esModule", { value: true });
62+
exports.publicProcedure = exports.router = exports.middleware = void 0;
63+
var server_1 = require("@trpc/server");
64+
var trpc = server_1.initTRPC.create();
65+
exports.middleware = trpc.middleware;
66+
exports.router = trpc.router;
67+
exports.publicProcedure = trpc.procedure;
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
//// [tests/cases/compiler/declarationEmitIsolatedDeclarationErrorNotEmittedForNonEmittedFile.ts] ////
2+
3+
=== node_modules/@trpc/server/internals/config.d.ts ===
4+
export interface RootConfig<T> {
5+
>RootConfig : Symbol(RootConfig, Decl(config.d.ts, 0, 0))
6+
>T : Symbol(T, Decl(config.d.ts, 0, 28))
7+
8+
prop: T;
9+
>prop : Symbol(RootConfig.prop, Decl(config.d.ts, 0, 32))
10+
>T : Symbol(T, Decl(config.d.ts, 0, 28))
11+
}
12+
=== node_modules/@trpc/server/internals/utils.d.ts ===
13+
export interface ErrorFormatterShape<T={}> {
14+
>ErrorFormatterShape : Symbol(ErrorFormatterShape, Decl(utils.d.ts, 0, 0))
15+
>T : Symbol(T, Decl(utils.d.ts, 0, 37))
16+
17+
prop: T;
18+
>prop : Symbol(ErrorFormatterShape.prop, Decl(utils.d.ts, 0, 44))
19+
>T : Symbol(T, Decl(utils.d.ts, 0, 37))
20+
}
21+
export type PickFirstDefined<TType, TPick> = undefined extends TType
22+
>PickFirstDefined : Symbol(PickFirstDefined, Decl(utils.d.ts, 2, 1))
23+
>TType : Symbol(TType, Decl(utils.d.ts, 3, 29))
24+
>TPick : Symbol(TPick, Decl(utils.d.ts, 3, 35))
25+
>TType : Symbol(TType, Decl(utils.d.ts, 3, 29))
26+
27+
? undefined extends TPick
28+
>TPick : Symbol(TPick, Decl(utils.d.ts, 3, 35))
29+
30+
? never
31+
: TPick
32+
>TPick : Symbol(TPick, Decl(utils.d.ts, 3, 35))
33+
34+
: TType;
35+
>TType : Symbol(TType, Decl(utils.d.ts, 3, 29))
36+
37+
export interface ErrorFormatter<T={},U={}> {
38+
>ErrorFormatter : Symbol(ErrorFormatter, Decl(utils.d.ts, 7, 10))
39+
>T : Symbol(T, Decl(utils.d.ts, 8, 32))
40+
>U : Symbol(U, Decl(utils.d.ts, 8, 37))
41+
42+
prop: [T, U];
43+
>prop : Symbol(ErrorFormatter.prop, Decl(utils.d.ts, 8, 44))
44+
>T : Symbol(T, Decl(utils.d.ts, 8, 32))
45+
>U : Symbol(U, Decl(utils.d.ts, 8, 37))
46+
}
47+
export interface DefaultErrorShape<T={}> {
48+
>DefaultErrorShape : Symbol(DefaultErrorShape, Decl(utils.d.ts, 10, 1))
49+
>T : Symbol(T, Decl(utils.d.ts, 11, 35))
50+
51+
prop: T;
52+
>prop : Symbol(DefaultErrorShape.prop, Decl(utils.d.ts, 11, 42))
53+
>T : Symbol(T, Decl(utils.d.ts, 11, 35))
54+
}
55+
=== node_modules/@trpc/server/middleware.d.ts ===
56+
export interface MiddlewareFunction<T={},U={}> {
57+
>MiddlewareFunction : Symbol(MiddlewareFunction, Decl(middleware.d.ts, 0, 0))
58+
>T : Symbol(T, Decl(middleware.d.ts, 0, 36))
59+
>U : Symbol(U, Decl(middleware.d.ts, 0, 41))
60+
61+
prop: [T, U];
62+
>prop : Symbol(MiddlewareFunction.prop, Decl(middleware.d.ts, 0, 48))
63+
>T : Symbol(T, Decl(middleware.d.ts, 0, 36))
64+
>U : Symbol(U, Decl(middleware.d.ts, 0, 41))
65+
}
66+
export interface MiddlewareBuilder<T={},U={}> {
67+
>MiddlewareBuilder : Symbol(MiddlewareBuilder, Decl(middleware.d.ts, 2, 1))
68+
>T : Symbol(T, Decl(middleware.d.ts, 3, 35))
69+
>U : Symbol(U, Decl(middleware.d.ts, 3, 40))
70+
71+
prop: [T, U];
72+
>prop : Symbol(MiddlewareBuilder.prop, Decl(middleware.d.ts, 3, 47))
73+
>T : Symbol(T, Decl(middleware.d.ts, 3, 35))
74+
>U : Symbol(U, Decl(middleware.d.ts, 3, 40))
75+
}
76+
=== node_modules/@trpc/server/index.d.ts ===
77+
import { RootConfig } from './internals/config';
78+
>RootConfig : Symbol(RootConfig, Decl(index.d.ts, 0, 8))
79+
80+
import { ErrorFormatterShape, PickFirstDefined, ErrorFormatter, DefaultErrorShape } from './internals/utils';
81+
>ErrorFormatterShape : Symbol(ErrorFormatterShape, Decl(index.d.ts, 1, 8))
82+
>PickFirstDefined : Symbol(PickFirstDefined, Decl(index.d.ts, 1, 29))
83+
>ErrorFormatter : Symbol(ErrorFormatter, Decl(index.d.ts, 1, 47))
84+
>DefaultErrorShape : Symbol(DefaultErrorShape, Decl(index.d.ts, 1, 63))
85+
86+
declare class TRPCBuilder<TParams> {
87+
>TRPCBuilder : Symbol(TRPCBuilder, Decl(index.d.ts, 1, 109))
88+
>TParams : Symbol(TParams, Decl(index.d.ts, 2, 26))
89+
90+
create<TOptions extends Record<string, any>>(): {
91+
>create : Symbol(TRPCBuilder.create, Decl(index.d.ts, 2, 36))
92+
>TOptions : Symbol(TOptions, Decl(index.d.ts, 3, 11))
93+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
94+
95+
procedure: {};
96+
>procedure : Symbol(procedure, Decl(index.d.ts, 3, 53))
97+
98+
middleware: <TNewParams extends Record<string, any>>(fn: import("./middleware").MiddlewareFunction<{
99+
>middleware : Symbol(middleware, Decl(index.d.ts, 4, 22))
100+
>TNewParams : Symbol(TNewParams, Decl(index.d.ts, 5, 21))
101+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
102+
>fn : Symbol(fn, Decl(index.d.ts, 5, 61))
103+
>MiddlewareFunction : Symbol(MiddlewareFunction, Decl(middleware.d.ts, 0, 0))
104+
105+
_config: RootConfig<{
106+
>_config : Symbol(_config, Decl(index.d.ts, 5, 108))
107+
>RootConfig : Symbol(RootConfig, Decl(index.d.ts, 0, 8))
108+
109+
errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
110+
>errorShape : Symbol(errorShape, Decl(index.d.ts, 6, 33))
111+
>ErrorFormatterShape : Symbol(ErrorFormatterShape, Decl(index.d.ts, 1, 8))
112+
>PickFirstDefined : Symbol(PickFirstDefined, Decl(index.d.ts, 1, 29))
113+
>TOptions : Symbol(TOptions, Decl(index.d.ts, 3, 11))
114+
>ErrorFormatter : Symbol(ErrorFormatter, Decl(index.d.ts, 1, 47))
115+
>TParams : Symbol(TParams, Decl(index.d.ts, 2, 26))
116+
>TParams : Symbol(TParams, Decl(index.d.ts, 2, 26))
117+
>DefaultErrorShape : Symbol(DefaultErrorShape, Decl(index.d.ts, 1, 63))
118+
119+
}>;
120+
}, TNewParams>) => import("./middleware").MiddlewareBuilder<{
121+
>TNewParams : Symbol(TNewParams, Decl(index.d.ts, 5, 21))
122+
>MiddlewareBuilder : Symbol(MiddlewareBuilder, Decl(middleware.d.ts, 2, 1))
123+
124+
_config: RootConfig<{
125+
>_config : Symbol(_config, Decl(index.d.ts, 9, 69))
126+
>RootConfig : Symbol(RootConfig, Decl(index.d.ts, 0, 8))
127+
128+
errorShape: ErrorFormatterShape<PickFirstDefined<TOptions["errorFormatter"], ErrorFormatter<TParams["ctx"] extends object ? TParams["ctx"] : object, DefaultErrorShape>>>;
129+
>errorShape : Symbol(errorShape, Decl(index.d.ts, 10, 33))
130+
>ErrorFormatterShape : Symbol(ErrorFormatterShape, Decl(index.d.ts, 1, 8))
131+
>PickFirstDefined : Symbol(PickFirstDefined, Decl(index.d.ts, 1, 29))
132+
>TOptions : Symbol(TOptions, Decl(index.d.ts, 3, 11))
133+
>ErrorFormatter : Symbol(ErrorFormatter, Decl(index.d.ts, 1, 47))
134+
>TParams : Symbol(TParams, Decl(index.d.ts, 2, 26))
135+
>TParams : Symbol(TParams, Decl(index.d.ts, 2, 26))
136+
>DefaultErrorShape : Symbol(DefaultErrorShape, Decl(index.d.ts, 1, 63))
137+
138+
}>;
139+
}, TNewParams>;
140+
>TNewParams : Symbol(TNewParams, Decl(index.d.ts, 5, 21))
141+
142+
router: {};
143+
>router : Symbol(router, Decl(index.d.ts, 13, 23))
144+
145+
};
146+
}
147+
148+
export declare const initTRPC: TRPCBuilder<object>;
149+
>initTRPC : Symbol(initTRPC, Decl(index.d.ts, 18, 20))
150+
>TRPCBuilder : Symbol(TRPCBuilder, Decl(index.d.ts, 1, 109))
151+
152+
export {};
153+
=== index.ts ===
154+
import { initTRPC } from "@trpc/server";
155+
>initTRPC : Symbol(initTRPC, Decl(index.ts, 0, 8))
156+
157+
const trpc = initTRPC.create();
158+
>trpc : Symbol(trpc, Decl(index.ts, 2, 5))
159+
>initTRPC.create : Symbol(TRPCBuilder.create, Decl(index.d.ts, 2, 36))
160+
>initTRPC : Symbol(initTRPC, Decl(index.ts, 0, 8))
161+
>create : Symbol(TRPCBuilder.create, Decl(index.d.ts, 2, 36))
162+
163+
export const middleware = trpc.middleware;
164+
>middleware : Symbol(middleware, Decl(index.ts, 4, 12))
165+
>trpc.middleware : Symbol(middleware, Decl(index.d.ts, 4, 22))
166+
>trpc : Symbol(trpc, Decl(index.ts, 2, 5))
167+
>middleware : Symbol(middleware, Decl(index.d.ts, 4, 22))
168+
169+
export const router = trpc.router;
170+
>router : Symbol(router, Decl(index.ts, 5, 12))
171+
>trpc.router : Symbol(router, Decl(index.d.ts, 13, 23))
172+
>trpc : Symbol(trpc, Decl(index.ts, 2, 5))
173+
>router : Symbol(router, Decl(index.d.ts, 13, 23))
174+
175+
export const publicProcedure = trpc.procedure;
176+
>publicProcedure : Symbol(publicProcedure, Decl(index.ts, 6, 12))
177+
>trpc.procedure : Symbol(procedure, Decl(index.d.ts, 3, 53))
178+
>trpc : Symbol(trpc, Decl(index.ts, 2, 5))
179+
>procedure : Symbol(procedure, Decl(index.d.ts, 3, 53))
180+

0 commit comments

Comments
 (0)