Skip to content

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

Closed
papb wants to merge 4 commits into
mmkal:mainfrom
papb:expect-type-this-param
Closed

fix(expect-type): check this param in functions#252
papb wants to merge 4 commits into
mmkal:mainfrom
papb:expect-type-this-param

Conversation

@papb

@papb papb commented Jan 24, 2022

Copy link
Copy Markdown
Contributor

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?

@mmkal mmkal left a comment

Copy link
Copy Markdown
Owner

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
Copy Markdown
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’)!

@papb papb Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

codecov-commenter commented Jan 25, 2022

Copy link
Copy Markdown

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

papb commented Jun 5, 2022

Copy link
Copy Markdown
Contributor Author

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

@mmkal

mmkal commented Oct 23, 2022

Copy link
Copy Markdown
Owner

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