chore: remove some casts from filter

This commit is contained in:
alina 🌸 2023-09-24 04:26:28 +03:00
parent 7a41950632
commit 6279126439
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
7 changed files with 23 additions and 7 deletions

View file

@ -1,4 +1,5 @@
import { MtArgumentError } from '@mtcute/core'
import { isPresent } from '@mtcute/core/utils'
import { TelegramClient } from '../../client'
import { InputPeerLike, Message } from '../../types'
@ -37,5 +38,5 @@ export async function getMessageGroup(
if (!groupedId) throw new MtArgumentError('This message is not grouped')
return messages.filter((it) => it && it.groupedId?.eq(groupedId)) as Message[]
return messages.filter(isPresent).filter((it) => it.groupedId?.eq(groupedId))
}

View file

@ -1,4 +1,5 @@
import { tl } from '@mtcute/core'
import { isPresent } from '@mtcute/core/utils'
import { MessageEntity } from '../messages'
import { makeInspectable } from '../utils'
@ -36,9 +37,7 @@ export class TermsOfService {
* Terms of Service entities text
*/
get entities(): ReadonlyArray<MessageEntity> {
return (this._entities ??= this.tos.entities
.map((it) => MessageEntity._parse(it))
.filter((it) => it !== null) as MessageEntity[])
return (this._entities ??= this.tos.entities.map((it) => MessageEntity._parse(it)).filter(isPresent))
}
}

View file

@ -0,0 +1,9 @@
export * from './file-utils'
export * from './inline-utils'
export * from './misc-utils'
export * from './peer-utils'
export * from './rps-meter'
export * from './stream-utils'
export * from './updates-utils'
export * from './voice-utils'
export * from '@mtcute/core/utils'

View file

@ -5,6 +5,7 @@
},
"include": [
"./src",
"./tests"
"./tests",
"./utils.ts"
]
}

4
packages/client/utils.ts Normal file
View file

@ -0,0 +1,4 @@
// this file only exists as a hint to IDEs that we can use @mtcute/core/utils instead of @mtcute/core/src/utils.
// it is not present in the built package, just a DX improvement
export * from './src/utils'

View file

@ -3,6 +3,7 @@ import Long from 'long'
import { describe, it } from 'mocha'
import { FormattedString, MessageEntity, tl } from '@mtcute/client'
import { isPresent } from '@mtcute/client/utils'
import { html, HtmlMessageEntityParser } from '../src'
@ -21,7 +22,7 @@ const createEntity = <T extends tl.TypeMessageEntity['_']>(
}
const createEntities = (entities: tl.TypeMessageEntity[]): MessageEntity[] => {
return entities.map((it) => MessageEntity._parse(it)).filter((it) => it !== null) as MessageEntity[]
return entities.map((it) => MessageEntity._parse(it)).filter(isPresent)
}
describe('HtmlMessageEntityParser', () => {

View file

@ -3,6 +3,7 @@ import Long from 'long'
import { describe, it } from 'mocha'
import { FormattedString, MessageEntity, tl } from '@mtcute/client'
import { isPresent } from '@mtcute/client/utils'
import { MarkdownMessageEntityParser, md } from '../src'
@ -21,7 +22,7 @@ const createEntity = <T extends tl.TypeMessageEntity['_']>(
}
const createEntities = (entities: tl.TypeMessageEntity[]): MessageEntity[] => {
return entities.map((it) => MessageEntity._parse(it)).filter((it) => it !== null) as MessageEntity[]
return entities.map((it) => MessageEntity._parse(it)).filter(isPresent)
}
describe('MarkdownMessageEntityParser', () => {