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 type assertion #3

Merged
merged 5 commits into from
Dec 2, 2021
Merged

Fix type assertion #3

merged 5 commits into from
Dec 2, 2021

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Oct 13, 2021

close #2

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

As title

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Oct 13, 2021
@JounQin JounQin mentioned this pull request Oct 13, 2021
4 tasks
Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

It looks like there is a failing test 🤔

not ok 23 should call `test` if the given node is a valid element (2)
  ---
    operator: equal
    expected: false
    actual:   true
    stack: |-
      Error: should call `test` if the given node is a valid element (2)
          at Test.assert [as _assert] (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:311:54)
          at Test.bound [as _assert] (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:96:32)
          at Test.strictEqual (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:475:10)
          at Test.bound [as equal] (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:96:32)
          at Test.<anonymous> (file:///home/runner/work/hast-util-is-element/hast-util-is-element/test.js:153:8)
          at Test.bound [as _cb] (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:96:32)
          at Test.run (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:114:31)
          at Test.bound [as run] (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:96:32)
          at Test._end (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:217:11)
          at Test.bound [as _end] (/home/runner/work/hast-util-is-element/hast-util-is-element/node_modules/tape/lib/test.js:96:32)
  ...

https://github.com/syntax-tree/hast-util-is-element/pull/3/checks?check_run_id=3882934738#step:5:51

@JounQin
Copy link
Member Author

JounQin commented Oct 13, 2021

It looks like there is a failing test 🤔

Checking, I don't get this error on gitpod.io

@JounQin
Copy link
Member Author

JounQin commented Oct 13, 2021

@ChristianMurphy It should be working now.

test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
test.js Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@JounQin
Copy link
Member Author

JounQin commented Oct 18, 2021

ping @wooorm

@@ -56,8 +61,10 @@ export const isElement =
* When a `parent` node is known the `index` of node should also be given.
*
* @type {(
* (<T extends Element>(node: unknown, test: T['tagName']|TestFunctionPredicate<T>|Array.<T['tagName']|TestFunctionPredicate<T>>, index?: number, parent?: Parent, context?: unknown) => node is T) &
* ((node?: unknown, test?: Test, index?: number, parent?: Parent, context?: unknown) => boolean)
* (() => false) &
Copy link
Member Author

Choose a reason for hiding this comment

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

I still think we should remove this in typings.

Copy link
Member

Choose a reason for hiding this comment

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

What is the benefit in removing it?
The benefit in having it is that it matches how the code works. Generally, types should match the code. Why deviate from the code and introduce a breaking change?

Copy link
Member Author

@JounQin JounQin Dec 1, 2021

Choose a reason for hiding this comment

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

Generally, types should match the code.

TypeScript should be stricter than codes, the benefit is that isElement() is always meaningless in practice, and you should not use it at all. For example, parseInt(num) or parseInt() are valid in js, but error in ts.

introduce a breaking change

Personally, I won't say updating better practice types as breaking change.

index.test-d.ts Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
@JounQin
Copy link
Member Author

JounQin commented Oct 21, 2021

@wooorm Please help to review again.

@JounQin
Copy link
Member Author

JounQin commented Dec 1, 2021

ping @wooorm

index.test-d.ts Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
index.test-d.ts Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
index.js Show resolved Hide resolved
@@ -56,8 +61,10 @@ export const isElement =
* When a `parent` node is known the `index` of node should also be given.
*
* @type {(
* (<T extends Element>(node: unknown, test: T['tagName']|TestFunctionPredicate<T>|Array.<T['tagName']|TestFunctionPredicate<T>>, index?: number, parent?: Parent, context?: unknown) => node is T) &
* ((node?: unknown, test?: Test, index?: number, parent?: Parent, context?: unknown) => boolean)
* (() => false) &
Copy link
Member

Choose a reason for hiding this comment

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

What is the benefit in removing it?
The benefit in having it is that it matches how the code works. Generally, types should match the code. Why deviate from the code and introduce a breaking change?

index.test-d.ts Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
JounQin and others added 2 commits December 1, 2021 19:45
Co-authored-by: Titus <tituswormer@gmail.com>
Co-authored-by: Titus <tituswormer@gmail.com>
@wooorm wooorm changed the title fix: correct type assertion for isElement Fix type assertion Dec 2, 2021
@wooorm wooorm merged commit 65922fc into syntax-tree:main Dec 2, 2021
@wooorm wooorm added the 💪 phase/solved Post is done label Dec 2, 2021
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Dec 2, 2021
@wooorm
Copy link
Member

wooorm commented Dec 2, 2021

Thanks, released!

@wooorm wooorm added ☂️ area/types This affects typings 🐛 type/bug This is a problem 👶 semver/patch This is a backwards-compatible fix labels Dec 2, 2021
@JounQin JounQin deleted the fix/typings branch December 3, 2021 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 💪 phase/solved Post is done 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem
Development

Successfully merging this pull request may close these issues.

type assertion seems not working in ts
3 participants