exercism / typescript

Exercism exercises in TypeScript.
https://exercism.org/tracks/typescript
MIT License
148 stars 160 forks source link

Updating list-ops test generic types parameters #1463

Closed Shoghy closed 5 months ago

Shoghy commented 5 months ago

I added and deleted generic type parameters from the list-ops exercise tests.

I did this because I was having problems compiling the code and I also noticed that several generic types were redudant, considering that the List class has a generic type like Array.

I will list 2 of the changed tests and the reasons why I added or removed the generic type parameter, the other tests were changed for the same reasons:

/*...*/
xit('list to empty list', () => {
  const list1 = List.create<number>()
  const list2 = List.create(1, 2, 3, 4)
  expect(list1.append(list2)).toEqual(list2)
})
/*...*/

In this first test I added the generic type parameter <number> to list1 so that, even though the constant list1 has no elements, TypeScript understands that it stores the same type value as list2. I did not add <number> to list2 because the type of value it stores is automatically deduced by the parameters sent in the create function.


/*...*/
describe('filter list returning only values that satisfy the filter function', () => {
  xit('empty list', () => {
    const list1 = List.create<number>()
    expect(list1.filter((el) => el % 2 === 1)).toHaveValues()
  })
/*...*/

In this case I understand that <number> in filter refers to the type of value that the list returned by filter will store, however this is not necessary if List has a generic type, since the returned list will store the same type of value as the original list.

github-actions[bot] commented 5 months ago

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use [this link](https://forum.exercism.org/new-topic?title=Updating%20list-ops%20test%20generic%20types%20parameters&body=I%20added%20and%20deleted%20generic%20type%20parameters%20from%20the%20list-ops%20exercise%20tests.%0D%0A%0D%0AI%20did%20this%20because%20I%20was%20having%20problems%20compiling%20the%20code%20and%20I%20also%20noticed%20that%20several%20generic%20types%20were%20redudant,%20considering%20that%20the%20%60List%60%20class%20has%20a%20generic%20type%20like%20%60Array%60.%0D%0A%0D%0AI%20will%20list%202%20of%20the%20changed%20tests%20and%20the%20reasons%20why%20I%20added%20or%20removed%20the%20generic%20type%20parameter,%20the%20other%20tests%20were%20changed%20for%20the%20same%20reasons:%0D%0A%0D%0A%60%60%60ts%0D%0A/*...*/%0D%0Axit('list%20to%20empty%20list',%20()%20=%3E%20%7B%0D%0A%20%20const%20list1%20=%20List.create%3Cnumber%3E()%0D%0A%20%20const%20list2%20=%20List.create(1,%202,%203,%204)%0D%0A%20%20expect(list1.append(list2)).toEqual(list2)%0D%0A%7D)%0D%0A/*...*/%0D%0A%60%60%60%0D%0AIn%20this%20first%20test%20I%20added%20the%20generic%20type%20parameter%20%60%3Cnumber%3E%60%20to%20%60list1%60%20so%20that,%20even%20though%20the%20constant%20%60list1%60%20has%20no%20elements,%20TypeScript%20understands%20that%20it%20stores%20the%20same%20type%20value%20as%20%60list2%60.%20I%20did%20not%20add%20%60%3Cnumber%3E%60%20to%20%60list2%60%20because%20the%20type%20of%20value%20it%20stores%20is%20automatically%20deduced%20by%20the%20parameters%20sent%20in%20the%20%60create%60%20function.%0D%0A___%0D%0A%0D%0A%60%60%60ts%0D%0A/*...*/%0D%0Adescribe('filter%20list%20returning%20only%20values%20that%20satisfy%20the%20filter%20function',%20()%20=%3E%20%7B%0D%0A%20%20xit('empty%20list',%20()%20=%3E%20%7B%0D%0A%20%20%20%20const%20list1%20=%20List.create%3Cnumber%3E()%0D%0A%20%20%20%20expect(list1.filter((el)%20=%3E%20el%20%25%202%20===%201)).toHaveValues()%0D%0A%20%20%7D)%0D%0A/*...*/%0D%0A%60%60%60%0D%0AIn%20this%20case%20I%20understand%20that%20%60%3Cnumber%3E%60%20in%20%60filter%60%20refers%20to%20the%20type%20of%20value%20that%20the%20list%20returned%20by%20%60filter%60%20will%20store,%20however%20this%20is%20not%20necessary%20if%20%60List%60%20has%20a%20generic%20type,%20since%20the%20returned%20list%20will%20store%20the%20same%20type%20of%20value%20as%20the%20original%20list.&category=typescript ) to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

If you're interested in learning more about this auto-responder, please read this blog post.


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

Shoghy commented 5 months ago

@SleeplessByte Tagging you since you requested it here