'LINQ in typescript or any alternative

I have the following code in c# that i want to use in typescript to show data in grid. Is there any way that i can run the following LINQ code in typescript? if not exactly , are there any workarounds?

var repaymentplan1 = from repaymentplan in AssetsRepaymentPlan.m_current
    group repaymentplan by new
    {
        repaymentplan.PRPLRPMTPLAN.REPAYMENTPLANID,
        repaymentplan.PRPLRPMTPLAN.RENTALDTE
    } into g

    select new
    {
        REPAYMENTPLANID = g.Key.REPAYMENTPLANID,
        CONTRACTDUEDATE = g.Key.RENTALDTE,
        CONTRACTINTERESTAMOUNT = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.INTERESTAMT),
        CONTRACTPRINCIPALAMOUNT = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.PRINCIPALAMT),
        CONTRACTPRINCIPALOSAMOUNT = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.PRINCIPALOUTSTANDINGAMT),
        CONTRACTRENTALAMT = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.RENTALAMT),
        CONTRACTRENTALTAX = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.GSTAMT),
        CMPRECEIVABLEAMT = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.RENTALAMT),
        REGISTRATIONAMT = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.REGISTRATIONAMT),
        INSURANCEAMT = g.Sum(repaymentplan => repaymentplan.PRPLRPMTPLAN.INSURANCEAMT),
        g.FirstOrDefault().PRPLRPMTPLAN.CHARGEAMT,
        TaxDetail = from taxDetails in g.Select(a => a.PRPLRPMTPLANTAX)
                    from taxDetail in taxDetails
                    group taxDetail by new
                    {
                        taxDetail.TAXTYPECDE,
                        taxDetail.AMNTCMPTCDE,
                        taxDetail.TAXRATE
                    } into gt
                    select new
                    {
                        gt.Key.AMNTCMPTCDE,
                        gt.Key.TAXTYPECDE,
                        gt.Key.TAXRATE,
                        BASEAMT = gt.Sum(tax => tax.BASEAMT),
                        TAXAMT = gt.Sum(tax => tax.TAXAMT),
                        CMPTTAXRCBLAMT = gt.Sum(tax => tax.CMPTTAXRCBLAMT),
                        ITCAMT = gt.Sum(tax => tax.ITCAMT),
                        ITCPCT = gt.Sum(tax => tax.ITCPCT),
                        TAXADJTAMT = gt.Sum(tax => tax.TAXADJTAMT),
                        TAXSETLAMT = gt.Sum(tax => tax.TAXSETLAMT)
                    }
    };


Solution 1:[1]

There is a TypeScript library for LINQ.

It is called ts-generic-collections-linq.

Providing strongly-typed, queryable collections such as:

  • List
  • Dictionary

Easy to use.

NPM

https://www.npmjs.com/package/ts-generic-collections-linq

Sample linq query:

//query to get owners by the sex/gender of their pets
let ownersByPetSex = owners.join(pets, owner => owner.id, pet => pet.ownerId, (x, y) => new OwnerPet(x,y))
                           .groupBy(x => [x.pet.sex])
                           .select(x =>  new OwnersByPetSex(x.groups[0], x.list.select(x => x.owner)));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cliff