I have schema that generated from prismabox, and while I using the schema and build d.ts. All type written repetitively instead using @import and cause error The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed
in large app.
How to solve this problem ?
Person.ts
import { Type } from "@sinclair/typebox";
export const PersonWhere = Type.Partial(
Type.Object({
id: Type.String(),
name: Type.String(),
statusId: Type.String(),
blacklist: Type.String(),
positionId: Type.String(),
...
}),
{ additionalProperties: false }
);
export const Person = Type.Object({
id: Type.String({ additionalProperties: false }),
name: Type.String({ additionalProperties: false }),
statusId: Type.String({ additionalProperties: false }),
...
});
export const PersonInputSelect = Type.Object({
id: Type.String({ additionalProperties: false }),
name: Type.String({ additionalProperties: false }),
statusId: Type.String({ additionalProperties: false }),
});
export const PersonInputOrderBy = Type.Object({
id: Type.String({ additionalProperties: false }),
departmentId: Type.String({ additionalProperties: false }),
groupId: Type.String({ additionalProperties: false }),
statusId: Type.String({ additionalProperties: false }),
});
export const PersonInputInclude = Type.Object({
id: Type.String({ additionalProperties: false }),
name: Type.String({ additionalProperties: false }),
barcodeId: Type.String({ additionalProperties: false }),
firstName: Type.String({ additionalProperties: false }),
lastName: Type.String({ additionalProperties: false }),
statusId: Type.String({ additionalProperties: false }),
});
index.ts
import { Type } from "@sinclair/typebox";
import {
Person,
PersonInputSelect,
PersonInputInclude,
PersonInputOrderBy,
PersonWhere,
} from "./Person";
export const schemas = {
person: {
name: "person",
model: Person,
select: PersonInputSelect,
include: PersonInputInclude,
where: PersonWhere,
orderBy: PersonInputOrderBy,
},
};
export const typeSchema = Type.Object({
person: Type.Object({
name: Type.Literal("person"),
model: Person,
select: PersonInputSelect,
include: PersonInputInclude,
where: PersonWhere,
orderBy: PersonInputOrderBy,
}),
});
tsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"disableSizeLimit": true,
"preserveSymlinks": true,
"moduleResolution": "Node",
"declaration": true,
"declarationDir": "./build",
"skipLibCheck": true,
"emitDeclarationOnly": true,
"noEmit": null
},
"include": ["src/index.ts"]
}
Generated file so big and repetitive
person.d.ts
export declare const PersonWhere: import("@sinclair/typebox").TObject<{
id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
statusId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
blacklist: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
positionId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
departmentId:
...
}>;
export declare const PersonInputSelect: import("@sinclair/typebox").TObject<{
id: import("@sinclair/typebox").TString;
name: import("@sinclair/typebox").TString;
statusId: import("@sinclair/typebox").TString;
}>;
export declare const PersonInputOrderBy: import("@sinclair/typebox").TObject<{
id: import("@sinclair/typebox").TString;
departmentId: import("@sinclair/typebox").TString;
groupId: import("@sinclair/typebox").TString;
statusId: import("@sinclair/typebox").TString;
}>;
export declare const PersonInputInclude: import("@sinclair/typebox").TObject<{
id: import("@sinclair/typebox").TString;
name: import("@sinclair/typebox").TString;
barcodeId: import("@sinclair/typebox").TString;
firstName: import("@sinclair/typebox").TString;
lastName: import("@sinclair/typebox").TString;
statusId: import("@sinclair/typebox").TString;
}>;
index.d.t.s
export declare const schemas: {
person: {
name: string;
model: import("@sinclair/typebox").TObject<{
id: import("@sinclair/typebox").TString;
name: import("@sinclair/typebox").TString;
...
orderBy: import("@sinclair/typebox").TObject<{
id: import("@sinclair/typebox").TString;
departmentId: import("@sinclair/typebox").TString;
groupId: import("@sinclair/typebox").TString;
statusId: import("@sinclair/typebox").TString;
}>;
};
};
export declare const typeSchema: import("@sinclair/typebox").TObject<{
person: import("@sinclair/typebox").TObject<{
... }>;
select: import("@sinclair/typebox").TObject<{
id: import("@sinclair/typebox").TString;
name: import("@sinclair/typebox").TString;
statusId: import("@sinclair/typebox").TString;
}>;
...
}>;
}>;
How to make tsc compile the typescript files using @import and don’t write the types repetitively.
Expected result
import { Person } from "./person"
export declare const schemas: {
person: {
name: string;
model: import("./person").Person;
select: import("./person").InputSelect;
.....
};
};
....
Repo : GitHub - fortezhuo/sample