@@ -142,6 +142,11 @@ export function intersperse<T>(input: T[], element: T): T[] {
142142 *
143143 * @internal
144144 */
145+ export function every < T , U extends T > ( array : readonly T [ ] , callback : ( element : T , index : number ) => element is U ) : array is readonly U [ ] ;
146+ /** @internal */
147+ export function every < T , U extends T > ( array : readonly T [ ] | undefined , callback : ( element : T , index : number ) => element is U ) : array is readonly U [ ] | undefined ;
148+ /** @internal */
149+ export function every < T > ( array : readonly T [ ] | undefined , callback : ( element : T , index : number ) => boolean ) : boolean ;
145150export function every < T > ( array : readonly T [ ] | undefined , callback : ( element : T , index : number ) => boolean ) : boolean {
146151 if ( array ) {
147152 for ( let i = 0 ; i < array . length ; i ++ ) {
@@ -478,7 +483,7 @@ export function sameFlatMap<T>(array: T[], mapfn: (x: T, i: number) => T | reado
478483/** @internal */
479484export function sameFlatMap < T > ( array : readonly T [ ] , mapfn : ( x : T , i : number ) => T | readonly T [ ] ) : readonly T [ ] ;
480485/** @internal */
481- export function sameFlatMap < T > ( array : T [ ] , mapfn : ( x : T , i : number ) => T | T [ ] ) : T [ ] {
486+ export function sameFlatMap < T > ( array : readonly T [ ] , mapfn : ( x : T , i : number ) => T | readonly T [ ] ) : readonly T [ ] {
482487 let result : T [ ] | undefined ;
483488 if ( array ) {
484489 for ( let i = 0 ; i < array . length ; i ++ ) {
@@ -703,11 +708,19 @@ export function concatenate<T>(array1: T[], array2: T[]): T[];
703708/** @internal */
704709export function concatenate < T > ( array1 : readonly T [ ] , array2 : readonly T [ ] ) : readonly T [ ] ;
705710/** @internal */
706- export function concatenate < T > ( array1 : T [ ] | undefined , array2 : T [ ] | undefined ) : T [ ] ;
711+ export function concatenate < T > ( array1 : T [ ] , array2 : T [ ] | undefined ) : T [ ] ; // eslint-disable-line @typescript-eslint/unified-signatures
712+ /** @internal */
713+ export function concatenate < T > ( array1 : T [ ] | undefined , array2 : T [ ] ) : T [ ] ; // eslint-disable-line @typescript-eslint/unified-signatures
714+ /** @internal */
715+ export function concatenate < T > ( array1 : readonly T [ ] , array2 : readonly T [ ] | undefined ) : readonly T [ ] ; // eslint-disable-line @typescript-eslint/unified-signatures
716+ /** @internal */
717+ export function concatenate < T > ( array1 : readonly T [ ] | undefined , array2 : readonly T [ ] ) : readonly T [ ] ; // eslint-disable-line @typescript-eslint/unified-signatures
707718/** @internal */
708- export function concatenate < T > ( array1 : readonly T [ ] | undefined , array2 : readonly T [ ] | undefined ) : readonly T [ ] ;
719+ export function concatenate < T > ( array1 : T [ ] | undefined , array2 : T [ ] | undefined ) : T [ ] | undefined ;
709720/** @internal */
710- export function concatenate < T > ( array1 : T [ ] , array2 : T [ ] ) : T [ ] {
721+ export function concatenate < T > ( array1 : readonly T [ ] | undefined , array2 : readonly T [ ] | undefined ) : readonly T [ ] | undefined ;
722+ /** @internal */
723+ export function concatenate < T > ( array1 : readonly T [ ] | undefined , array2 : readonly T [ ] | undefined ) : readonly T [ ] | undefined {
711724 if ( ! some ( array2 ) ) return array1 ;
712725 if ( ! some ( array1 ) ) return array2 ;
713726 return [ ...array1 , ...array2 ] ;
@@ -856,7 +869,7 @@ export function detectSortCaseSensitivity(array: readonly string[], useEslintOrd
856869/** @internal */
857870export function detectSortCaseSensitivity < T > ( array : readonly T [ ] , useEslintOrdering : boolean , getString : ( element : T ) => string ) : SortKind ;
858871/** @internal */
859- export function detectSortCaseSensitivity < T > ( array : readonly T [ ] , useEslintOrdering : boolean , getString ?: ( element : T ) => string ) : SortKind {
872+ export function detectSortCaseSensitivity < T > ( array : readonly T [ ] , useEslintOrdering ? : boolean , getString ?: ( element : T ) => string ) : SortKind {
860873 let kind = SortKind . Both ;
861874 if ( array . length < 2 ) return kind ;
862875 const caseSensitiveComparer = getString
@@ -915,7 +928,7 @@ export function compact<T>(array: T[]): T[]; // eslint-disable-line @typescript-
915928/** @internal */
916929export function compact < T > ( array : readonly T [ ] ) : readonly T [ ] ; // eslint-disable-line @typescript-eslint/unified-signatures
917930/** @internal */
918- export function compact < T > ( array : T [ ] ) : T [ ] {
931+ export function compact < T > ( array : readonly T [ ] ) : readonly T [ ] {
919932 let result : T [ ] | undefined ;
920933 if ( array ) {
921934 for ( let i = 0 ; i < array . length ; i ++ ) {
@@ -998,11 +1011,12 @@ export function append<T>(to: T[] | undefined, value: T | undefined): T[] | unde
9981011/** @internal */
9991012export function append < T > ( to : Push < T > , value : T | undefined ) : void ;
10001013/** @internal */
1001- export function append < T > ( to : T [ ] , value : T | undefined ) : T [ ] | undefined {
1002- if ( value === undefined ) return to ;
1014+ export function append < T > ( to : Push < T > | T [ ] | undefined , value : T | undefined ) : T [ ] | undefined {
1015+ // If to is Push<T>, return value is void, so safe to cast to T[].
1016+ if ( value === undefined ) return to as T [ ] ;
10031017 if ( to === undefined ) return [ value ] ;
10041018 to . push ( value ) ;
1005- return to ;
1019+ return to as T [ ] ;
10061020}
10071021
10081022/**
@@ -1315,7 +1329,7 @@ export function reduceLeft<T, U>(array: readonly T[] | undefined, f: (memo: U, v
13151329/** @internal */
13161330export function reduceLeft < T > ( array : readonly T [ ] , f : ( memo : T , value : T , i : number ) => T ) : T | undefined ;
13171331/** @internal */
1318- export function reduceLeft < T > ( array : T [ ] , f : ( memo : T , value : T , i : number ) => T , initial ?: T , start ?: number , count ?: number ) : T | undefined {
1332+ export function reduceLeft < T > ( array : readonly T [ ] | undefined , f : ( memo : T , value : T , i : number ) => T , initial ?: T , start ?: number , count ?: number ) : T | undefined {
13191333 if ( array && array . length > 0 ) {
13201334 const size = array . length ;
13211335 if ( size > 0 ) {
@@ -1883,11 +1897,7 @@ export function isNumber(x: unknown): x is number {
18831897}
18841898
18851899/** @internal */
1886- export function tryCast < TOut extends TIn , TIn = any > ( value : TIn | undefined , test : ( value : TIn ) => value is TOut ) : TOut | undefined ;
1887- /** @internal */
1888- export function tryCast < T > ( value : T , test : ( value : T ) => boolean ) : T | undefined ;
1889- /** @internal */
1890- export function tryCast < T > ( value : T , test : ( value : T ) => boolean ) : T | undefined {
1900+ export function tryCast < TOut extends TIn , TIn = any > ( value : TIn | undefined , test : ( value : TIn ) => value is TOut ) : TOut | undefined {
18911901 return value !== undefined && test ( value ) ? value : undefined ;
18921902}
18931903
0 commit comments