-
-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating list-ops test generic types parameters #1477
Conversation
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 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 I have rebased this for you. You must also update |
How do I test that file so I can be sure my changes are all right? |
@Shoghy from CONTRIBUTING.md
So in your case it would be ASSIGNMENT=practice/list-ops corepack yarn test or if you are on windows corepack yarn dlx cross-env ASSIGNMENT=practice/two-fer corepack yarn test |
I'll reformat the file now: /format |
The "Format code" action has started running. |
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
return new Cons(item, this) | ||
return new Cons(item, this) as Cons<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? Doesn't new Cons(item, this)
already infer Const<T>
? If not, shouldn't it be new Cons<T>(item, this)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case Cons
would be of type Cons<T | undefined>
, however because of how Null
works the undefined
part can be omitted, and since is of type Cons<T | undefined>
using new Cons<T>(item, this)
throws an error on TypeScript.
public readonly value: unknown, | ||
public next: Cons = Null | ||
public readonly value: T, | ||
public next: Cons<T> = Null as Cons<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to define it as:
public next: Cons<T> | Cons<undefined>
instead of needing the as Cons<T>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can make the code a little bit messier with the types, and the only method where this is important is get
, so that's why I made the return value of get
be T | undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think overall it's a net improvement (less explicit types in the tests), but I am not completely convinced about the proof solution. However let's get this merged and make further improvements in future PRs
Thank you for working on this!
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 likeArray
.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:
In this first test I added the generic type parameter
<number>
tolist1
so that, even though the constantlist1
has no elements, TypeScript understands that it stores the same type value aslist2
. I did not add<number>
tolist2
because the type of value it stores is automatically deduced by the parameters sent in thecreate
function.In this case I understand that
<number>
infilter
refers to the type of value that the list returned byfilter
will store, however this is not necessary ifList
has a generic type, since the returned list will store the same type of value as the original list.