Skip to content
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

fix(expect-type): check this param in functions #252

Closed
wants to merge 4 commits into from

Conversation

papb
Copy link
Contributor

@papb papb commented Jan 24, 2022

Closes mmkal/expect-type#7

I also added .thisParam. So this PR is a mix of fix and feat. Should it have been two separate PRs?

Copy link
Owner

@mmkal mmkal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully GitHub actions will warn about out of sync readme, but we’ll see…

expectTypeOf<AnyThisParam>().thisParam.toBeAny();
})

test('Of course, `.toEqualTypeOf` also distinguishes the `this` argument between functions', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test('Of course, `.toEqualTypeOf` also distinguishes the `this` argument between functions', () => {
test('`.toEqualTypeOf` also distinguishes the `this` argument between functions', () => {

I also wonder whether this test is stretching a bit to be part of the docs. If I were someone who used this, I would probably just assume it worked (which I suppose is why you added ‘of course’)!

Copy link
Contributor Author

@papb papb Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to take long. Is it possible to make a test that doesn't get included in the docs?

})

test('Of course, `.toEqualTypeOf` also distinguishes the `this` argument between functions', () => {
type NoThisParam = (a: number) => void
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m glad you’ve done them, but I’m not sure so many tests are needed. Should be sufficient to show that the this param matters by comparing two. After that point isn’t it just re-testing DeepBrand?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be right, but still I'd prefer to have them all to be honest. I may be re-testing DeepBrand in a way, but I prefer the test to be fully self-contained. If this test passes, I am sure my feature works as expected. If I rely on DeepBrand implicitly, something might change in the DeepBrand implementation and the test could still pass. I want the test to be a complete specification of what the feature must do...

type UnknownThisParam = (this: unknown, a: number) => void
type AnyThisParam = (this: any, a: number) => void

// `NoThisParam` and `UnknownThisParam` are the only ones that should be considered equivalent.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 96950be

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2022

Codecov Report

Merging #252 (7b5c7e3) into main (db7c65e) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     mmkal/ts#252   +/-   ##
=======================================
  Coverage   99.88%   99.88%           
=======================================
  Files          46       46           
  Lines         907      907           
  Branches      165      165           
=======================================
  Hits          906      906           
  Misses          1        1           
Impacted Files Coverage Δ
packages/expect-type/src/index.ts 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db7c65e...7b5c7e3. Read the comment docs.

@papb
Copy link
Contributor Author

papb commented Jun 5, 2022

Hi @mmkal, sorry to take long, my last commit fixed the create change files / run check, everything green now.

@mmkal
Copy link
Owner

mmkal commented Oct 23, 2022

Closing in favour of mmkal/expect-type#15

@mmkal mmkal closed this Oct 23, 2022
mmkal added a commit to mmkal/expect-type that referenced this pull request Oct 23, 2022
Fixes #7

Porting over mmkal/ts#252 - thank you @papb for
creating that one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[expect-type] this param ignored in .toEqualTypeOf
3 participants