refactor(client): use ReadonlyArray for getter return types

This commit is contained in:
teidesu 2021-05-11 22:02:00 +03:00
parent 61778dba8e
commit d8cd13fd60
14 changed files with 17 additions and 17 deletions

View file

@ -36,5 +36,5 @@ export interface IMessageEntityParser {
* @param text Plain text
* @param entities Message entities that should be added to the text
*/
unparse(text: string, entities: MessageEntity[]): string
unparse(text: string, entities: ReadonlyArray<MessageEntity>): string
}

View file

@ -34,7 +34,7 @@ export class TermsOfService {
/**
* Terms of Service entities text
*/
get entities(): MessageEntity[] {
get entities(): ReadonlyArray<MessageEntity> {
if (!this._entities) {
this._entities = this.tos.entities
.map((it) => MessageEntity._parse(it))

View file

@ -71,7 +71,7 @@ export class RawDocument extends FileLocation {
*
* If there are no thumbnails, the array will be empty.
*/
get thumbnails(): Thumbnail[] {
get thumbnails(): ReadonlyArray<Thumbnail> {
if (!this._thumbnails) {
this._thumbnails = this.doc.thumbs
? this.doc.thumbs.map(

View file

@ -84,7 +84,7 @@ export class Photo extends FileLocation {
* **Note**: This list will also contain the largest thumbnail that is
* represented by the current object.
*/
get thumbnails(): Thumbnail[] {
get thumbnails(): ReadonlyArray<Thumbnail> {
if (!this._thumbnails) {
this._thumbnails = this.raw.sizes.map(
(sz) => new Thumbnail(this.client, this.raw, sz)

View file

@ -74,7 +74,7 @@ export class Poll {
/**
* List of answers in this poll
*/
get answers(): Poll.PollAnswer[] {
get answers(): ReadonlyArray<Poll.PollAnswer> {
if (!this._answers) {
const results = this.results?.results
@ -153,7 +153,7 @@ export class Poll {
* Format entities for {@link solution}, only available
* in case you have already answered
*/
get solutionEntities(): MessageEntity[] | null {
get solutionEntities(): ReadonlyArray<MessageEntity> | null {
if (!this.results) return null
if (!this._entities) {

View file

@ -57,7 +57,7 @@ export class DraftMessage {
/**
* Message text entities (may be empty)
*/
get entities(): MessageEntity[] {
get entities(): ReadonlyArray<MessageEntity> {
if (!this._entities) {
this._entities = []
if (this.raw.entities?.length) {

View file

@ -362,7 +362,7 @@ export class Message {
/**
* Message text/caption entities (may be empty)
*/
get entities(): MessageEntity[] {
get entities(): ReadonlyArray<MessageEntity> {
if (this._emptyError) throw this._emptyError
if (!this._entities) {

View file

@ -133,7 +133,7 @@ export class StickerSet {
* @throws MtCuteEmptyError
* In case this object does not contain info about stickers (i.e. {@link isFull} = false)
*/
get stickers(): StickerSet.StickerInfo[] {
get stickers(): ReadonlyArray<StickerSet.StickerInfo> {
if (!this.isFull) throw new MtCuteEmptyError()
if (!this._stickers) {

View file

@ -76,7 +76,7 @@ export class ChatPreview {
* and members that are inside your contacts list are
* ordered before others.
*/
get someMembers(): User[] {
get someMembers(): ReadonlyArray<User> {
if (!this._someMembers) {
this._someMembers = this.invite.participants
? this.invite.participants.map(

View file

@ -355,7 +355,7 @@ export class Chat {
* The list of reasons why this chat might be unavailable to some users.
* This field is available only in case {@link isRestricted} is `true`
*/
get restrictions(): tl.RawRestrictionReason[] | null {
get restrictions(): ReadonlyArray<tl.RawRestrictionReason> | null {
return 'restrictionReason' in this.peer
? this.peer.restrictionReason ?? null
: null

View file

@ -246,7 +246,7 @@ export class User {
* The list of reasons why this bot might be unavailable to some users.
* This field is available only in case *isRestricted* is `true`
*/
get restrictions(): tl.RawRestrictionReason[] | null {
get restrictions(): ReadonlyArray<tl.RawRestrictionReason> | null {
return this._user.restrictionReason ?? null
}

View file

@ -70,7 +70,7 @@ export class PollVoteUpdate {
* This might break at any time, but seems to be consistent for now.
* To get chosen answer indexes derived as before, use {@link chosenIndexesAuto}.
*/
get chosen(): Buffer[] {
get chosen(): ReadonlyArray<Buffer> {
return this.raw.options
}
@ -81,7 +81,7 @@ export class PollVoteUpdate {
*
* If something does not add up, {@link MtCuteUnsupportedError} is thrown
*/
get chosenIndexesAuto(): number[] {
get chosenIndexesAuto(): ReadonlyArray<number> {
return this.raw.options.map((buf) => {
if (buf.length > 1)
throw new MtCuteUnsupportedError('option had >1 byte')

View file

@ -169,14 +169,14 @@ export class HtmlMessageEntityParser implements IMessageEntityParser {
return [plainText, entities]
}
unparse(text: string, entities: MessageEntity[]): string {
unparse(text: string, entities: ReadonlyArray<MessageEntity>): string {
return this._unparse(text, entities)
}
// internal function that uses recursion to correctly process nested & overlapping entities
private _unparse(
text: string,
entities: MessageEntity[],
entities: ReadonlyArray<MessageEntity>,
entitiesOffset = 0,
offset = 0,
length = text.length

View file

@ -244,7 +244,7 @@ export class MarkdownMessageEntityParser implements IMessageEntityParser {
return [result, entities]
}
unparse(text: string, entities: MessageEntity[]): string {
unparse(text: string, entities: ReadonlyArray<MessageEntity>): string {
// keep track of positions of inserted escape symbols
const escaped: number[] = []
text = text.replace(TO_BE_ESCAPED, (s, pos: number) => {