TypeScript. Ошибка сборки.
Closed this issue · 11 comments
Проблема
Ошибка типизации при сборке проекта.
Последовательность действий
- Написал базовый проект по примерам из официального гитхаб-репозитория.
- Запустил скрипт: tsc
- Получил ошибку.
Окружение
Код
Весь лог ошибки
10 export declare type HearConditions<T> = (AllowArray<HearCondition<T, string | undefined>> | AllowArray<HearObjectCondition<T>>);
~
node_modules/.pnpm/@puregram+hear@2.0.2_puregram@2.22.1/node_modules/@puregram/hear/lib/types.d.ts:10:36
10 export declare type HearConditions<T> = (AllowArray<HearCondition<T, string | undefined>> | AllowArray<HearObjectCondition<T>>);
~
This type parameter might need an `extends Record<string, any>` constraint.
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/common/message-entities.d.ts:28:5 - error TS2416: Property 'with' in type 'MessageEntities' is not assignable to the same property in base type 'MessageEntity[]'.
Type '(payload: Partial<Known<TelegramMessageEntity>>) => MessageEntities' is not assignable to type '(index: number, value: MessageEntity) => MessageEntity[]'.
Types of parameters 'payload' and 'index' are incompatible.
Type 'number' has no properties in common with type 'Partial<Known<TelegramMessageEntity>>'.
28 with(payload: Partial<Known<Interfaces.TelegramMessageEntity>>): MessageEntities;
~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/common/structures/composer.d.ts:3:22 - error TS2417: Class static side 'typeof import("/root/titsex/telegram-image-bot/node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/common/structures/composer").Composer' incorrectly extends base class static side 'typeof import("/root/titsex/telegram-image-bot/node_modules/.pnpm/middleware-io@2.8.1/node_modules/middleware-io/lib/composer").Composer'.
The types of 'builder().middlewares' are incompatible between these types.
Type 'import("/root/titsex/telegram-image-bot/node_modules/.pnpm/middleware-io@2.8.1/node_modules/middleware-io/lib/types").Middleware<import("/root/titsex/telegram-image-bot/node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/context").Context>[]' is not assignable to type 'import("/root/titsex/telegram-image-bot/node_modules/.pnpm/middleware-io@2.8.1/node_modules/middleware-io/lib/types").Middleware<Context>[]'.
Type 'import("/root/titsex/telegram-image-bot/node_modules/.pnpm/middleware-io@2.8.1/node_modules/middleware-io/lib/types").Middleware<import("/root/titsex/telegram-image-bot/node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/context").Context>' is not assignable to type 'import("/root/titsex/telegram-image-bot/node_modules/.pnpm/middleware-io@2.8.1/node_modules/middleware-io/lib/types").Middleware<Context>'.
Type 'Context' is not assignable to type 'import("/root/titsex/telegram-image-bot/node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/context").Context'.
Type 'UnknownObject' is missing the following properties from type 'Context': telegram, updateType, is, [Symbol.toStringTag]
3 export declare class Composer<T extends Context> extends MiddlewareComposer<T> {
~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/common/structures/composer.d.ts:3:77 - error TS2344: Type 'T' does not satisfy the constraint 'UnknownObject'.
Type 'Context' is not assignable to type 'UnknownObject'.
Index signature for type 'string' is missing in type 'Context'.
3 export declare class Composer<T extends Context> extends MiddlewareComposer<T> {
~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chat-join-request.d.ts:21:11 - error TS2320: Interface 'ChatJoinRequestContext' cannot simultaneously extend types 'ChatJoinRequest' and 'ChatInviteControlMixin'.
Named property 'from' of types 'ChatJoinRequest' and 'ChatInviteControlMixin' are not identical.
21 interface ChatJoinRequestContext extends Constructor<ChatJoinRequestContext>, ChatJoinRequest, TargetMixin, SendMixin, ChatActionMixin, ChatInviteControlMixin, CloneMixin<ChatJoinRequestContext, ChatJoinRequestContextOptions> {
~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chat-join-request.d.ts:21:11 - error TS2320: Interface 'ChatJoinRequestContext' cannot simultaneously extend types 'ChatJoinRequest' and 'TargetMixin'.
Named property 'from' of types 'ChatJoinRequest' and 'TargetMixin' are not identical.
21 interface ChatJoinRequestContext extends Constructor<ChatJoinRequestContext>, ChatJoinRequest, TargetMixin, SendMixin, ChatActionMixin, ChatInviteControlMixin, CloneMixin<ChatJoinRequestContext, ChatJoinRequestContextOptions> {
~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chat-member.d.ts:20:11 - error TS2320: Interface 'ChatMemberContext' cannot simultaneously extend types 'ChatMemberUpdated' and 'ChatControlMixin'.
Named property 'from' of types 'ChatMemberUpdated' and 'ChatControlMixin' are not identical.
20 interface ChatMemberContext extends Constructor<ChatMemberContext>, ChatMemberUpdated, TargetMixin, SendMixin, ChatActionMixin, ChatControlMixin, CloneMixin<ChatMemberContext, ChatMemberContextOptions> {
~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chat-member.d.ts:20:11 - error TS2320: Interface 'ChatMemberContext' cannot simultaneously extend types 'ChatMemberUpdated' and 'TargetMixin'.
Named property 'from' of types 'ChatMemberUpdated' and 'TargetMixin' are not identical.
20 interface ChatMemberContext extends Constructor<ChatMemberContext>, ChatMemberUpdated, TargetMixin, SendMixin, ChatActionMixin, ChatControlMixin, CloneMixin<ChatMemberContext, ChatMemberContextOptions> {
~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chosen-inline-result.d.ts:25:11 - error TS2320: Interface 'ChosenInlineResultContext' cannot simultaneously extend types 'ChosenInlineResult' and 'ChatActionMixin'.
Named property 'senderId' of types 'ChosenInlineResult' and 'ChatActionMixin' are not identical.
25 interface ChosenInlineResultContext extends Constructor<ChosenInlineResultContext>, ChosenInlineResult, SendMixin, ChatActionMixin, CloneMixin<ChosenInlineResultContext, ChosenInlineResultContextOptions> {
~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chosen-inline-result.d.ts:25:11 - error TS2320: Interface 'ChosenInlineResultContext' cannot simultaneously extend types 'ChosenInlineResult' and 'SendMixin'.
Named property 'senderId' of types 'ChosenInlineResult' and 'SendMixin' are not identical.
25 interface ChosenInlineResultContext extends Constructor<ChosenInlineResultContext>, ChosenInlineResult, SendMixin, ChatActionMixin, CloneMixin<ChosenInlineResultContext, ChosenInlineResultContextOptions> {
~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/poll-answer.d.ts:21:11 - error TS2320: Interface 'PollAnswerContext' cannot simultaneously extend types 'PollAnswer' and 'ChatActionMixin'.
Named property 'senderId' of types 'PollAnswer' and 'ChatActionMixin' are not identical.
21 interface PollAnswerContext extends Constructor<PollAnswerContext>, PollAnswer, SendMixin, ChatActionMixin, CloneMixin<PollAnswerContext, PollAnswerContextOptions> {
~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/poll-answer.d.ts:21:11 - error TS2320: Interface 'PollAnswerContext' cannot simultaneously extend types 'PollAnswer' and 'SendMixin'.
Named property 'senderId' of types 'PollAnswer' and 'SendMixin' are not identical.
21 interface PollAnswerContext extends Constructor<PollAnswerContext>, PollAnswer, SendMixin, ChatActionMixin, CloneMixin<PollAnswerContext, PollAnswerContextOptions> {
~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/pre-checkout-query.d.ts:24:11 - error TS2320: Interface 'PreCheckoutQueryContext' cannot simultaneously extend types 'PreCheckoutQuery' and 'ChatActionMixin'.
Named property 'senderId' of types 'PreCheckoutQuery' and 'ChatActionMixin' are not identical.
24 interface PreCheckoutQueryContext extends Constructor<PreCheckoutQueryContext>, PreCheckoutQuery, SendMixin, ChatActionMixin, CloneMixin<PreCheckoutQueryContext, PreCheckoutQueryContextOptions> {
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/pre-checkout-query.d.ts:24:11 - error TS2320: Interface 'PreCheckoutQueryContext' cannot simultaneously extend types 'PreCheckoutQuery' and 'SendMixin'.
Named property 'senderId' of types 'PreCheckoutQuery' and 'SendMixin' are not identical.
24 interface PreCheckoutQueryContext extends Constructor<PreCheckoutQueryContext>, PreCheckoutQuery, SendMixin, ChatActionMixin, CloneMixin<PreCheckoutQueryContext, PreCheckoutQueryContextOptions> {
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/shipping-query.d.ts:17:11 - error TS2320: Interface 'ShippingQueryContext' cannot simultaneously extend types 'ShippingQuery' and 'ChatActionMixin'.
Named property 'senderId' of types 'ShippingQuery' and 'ChatActionMixin' are not identical.
17 interface ShippingQueryContext extends Constructor<ShippingQueryContext>, ShippingQuery, SendMixin, ChatActionMixin, CloneMixin<ShippingQueryContext, ShippingQueryContextOptions> {
~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/shipping-query.d.ts:17:11 - error TS2320: Interface 'ShippingQueryContext' cannot simultaneously extend types 'ShippingQuery' and 'SendMixin'.
Named property 'senderId' of types 'ShippingQuery' and 'SendMixin' are not identical.
17 interface ShippingQueryContext extends Constructor<ShippingQueryContext>, ShippingQuery, SendMixin, ChatActionMixin, CloneMixin<ShippingQueryContext, ShippingQueryContextOptions> {
~~~~~~~~~~~~~~~~~~~~
Found 16 errors in 9 files.
Errors Files
1 node_modules/.pnpm/@puregram+hear@2.0.2_puregram@2.22.1/node_modules/@puregram/hear/lib/types.d.ts:10
1 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/common/message-entities.d.ts:28
2 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/common/structures/composer.d.ts:3
2 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chat-join-request.d.ts:21
2 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chat-member.d.ts:20
2 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/chosen-inline-result.d.ts:25
2 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/poll-answer.d.ts:21
2 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/pre-checkout-query.d.ts:24
2 node_modules/.pnpm/puregram@2.22.1/node_modules/puregram/lib/contexts/shipping-query.d.ts:17```
Так как ответов я не получил, начал разбираться с проблемой сам.
Нашел причину ошибки сборки (отсутствие параметра "skipLibCheck" в "tsconfig.json")
Об этом нигде в инструкциях не написано, поэтому, прошу принять к сведению и добавить в инструкцию установки, как требуемый параметр - ("skipLibCheck": true).
Мой "tsconfig.json" для запуска проекта с использованием "puregram" (это для тех, кто столкнется с подобной ошибкой в будущем):
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
Хорошего коддинга!
ёмаё извини за игнор у меня гитхаббот в телеграме почему то не скинул это сообщение в лс
не совсем понимаю по какой причине вообще может не происходить билд, потому что когда я пытаюсь собрать проект с puregram - всё окей (вероятно, как раз из-за skipLibCheck)
спасибо! я отредактирую README и укажу о том, что skipLibCheck обязателен для устранения ошибок! <3
Теперь когда после исправления tsconfig.json я пытаюсь сделать сборку, используя @puregram/hear, выдает новую ошибку:
TypeError: Cannot read properties of undefined (reading 'builder')
Вот "tsconfig.json":
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"alwaysStrict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}
И само использование @puregram/hear:
import Logger from '@class/Logger'
import { MessageContext, Telegram } from 'puregram'
import { HearManager } from '@puregram/hear'
// import { modulesPath } from '@constants'
// import { collectModules } from '@utils'
const telegram = Telegram.fromToken(process.env.TOKEN as string)
const hearManager = new HearManager<MessageContext>()
const start = async () => {
// const modules = await collectModules(modulesPath)
telegram.updates.on('message', hearManager.middleware)
hearManager.hear(/^\/start$/i, Logger.info)
/* for (const module of modules) {
console.log(module)
hearManager.hear(module.regex, module.callback)
} */
telegram.updates
.startPolling()
.then(() => Logger.info('Bot has been successfully started'))
.catch(Logger.error)
}
start()
Я вроде ничего сверхъестественного не делаю, лишь создаю инстанс HearManager-а, и обрабатываю его middleware-ом событие message.
очень странно, поскольку как раз 2.1.0-rc.1
должно было это зафиксить (челики, которые сообщили мне об этом баге, говорили, что 2.1.0-rc.1
у @puregram/hear
пофиксил) 🤔
Попробую переустановить пакеты.
судя по всему у меня там каким то образом образовались циклические импорты (в самом puregram), ща спросонья попробую выявить их и пофиксить...
Благодарю. Буду ожидать обновления.
Сейчас попробую.