fix(codegen): fixed typings codegen, added a test

This commit is contained in:
teidesu 2022-07-23 05:03:38 +03:00
parent ad29b2af17
commit 2a97616d80
3 changed files with 16 additions and 2 deletions

View file

@ -339,7 +339,7 @@ export class BaseTelegramClient extends EventEmitter {
langCode: 'en', langCode: 'en',
...(opts.initConnectionOptions ?? {}), ...(opts.initConnectionOptions ?? {}),
apiId, apiId,
query: null, query: null as any,
} }
} }

View file

@ -99,7 +99,7 @@ export function generateTypescriptDefinitionsForTlEntry(
genericsIndex[it.name] = 1 genericsIndex[it.name] = 1
if (idx !== 0) genericsString += ', ' if (idx !== 0) genericsString += ', '
genericsString += `${it.name} extends ${tsType}` genericsString += `${it.name} extends ${tsType} = ${tsType}`
}) })
genericsString += '>' genericsString += '>'
} }

View file

@ -73,6 +73,20 @@ describe('generateReaderCodeForTlEntry', () => {
) )
}) })
it('generates code for constructors with arguments before flags field', () => {
test(
'poll#86e18161 id:long flags:# quiz:flags.3?true question:string = Poll;',
'var id=r.long(),',
'flags=r.uint();',
'return{',
"_:'poll',",
'id:id,',
'quiz:!!(flags&8),',
'question:r.string(),',
'}'
)
})
it('generates code for constructors with multiple flags fields', () => { it('generates code for constructors with multiple flags fields', () => {
test( test(
'updates.channelDifferenceEmpty#3e11affb flags:# final:flags.0?true pts:int timeout:flags.1?int flags2:# can_delete_channel:flags2.0?true = updates.ChannelDifference;', 'updates.channelDifferenceEmpty#3e11affb flags:# final:flags.0?true pts:int timeout:flags.1?int flags2:# can_delete_channel:flags2.0?true = updates.ChannelDifference;',