arogozine/LinqToTypeScript

max() on empty sequence from array throws

vgpro54321 opened this issue · 3 comments

Hello Guys,

IEnumerable<>.max() function in .NET returns null when sequence is empty (semantics maximum is unknown). LinqToTypeScript throws an error. Is this by design?

Anybody alive?

By the design.

See here,
https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.max?view=net-6.0#system-linq-enumerable-max(system-collections-generic-ienumerable((system-int32)))

under exceptions,
It throws InvalidOperationException if 'source contains no elements'

Only outlier to that are nullable numeric types - which would be number | null or similar in TS, I suppose. The library only supports max(this: IEnumerable<number>): number and TSC should error out if you pass anything else in sctrict mode.

Make sense, thank you!