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

Update typescript #216

Merged
merged 4 commits into from
Aug 9, 2023
Merged

Update typescript #216

merged 4 commits into from
Aug 9, 2023

Conversation

ChristianMurphy
Copy link
Member

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

First step towards moving most or all of the types into JSDoc.
Previously lack of overloads was a blocker.
TypeScript 5 includes overload syntax for JSDoc https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#overload-support-in-jsdoc

The full migration to JSDoc will be large, this is the first step towards that, ensuring the project still builds on TypeScript 5, and building it with TS5 by default.

@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 Mar 17, 2023
Comment on lines +50 to +53
/**
* @param {Node} tree
* @param {VFile} file
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

these are needed by type coverage, tree was considered an implicit any

Copy link
Member

Choose a reason for hiding this comment

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

Was TypeScript able to infer its type before? This seems like a regression in TypeScript.

Copy link
Member Author

@ChristianMurphy ChristianMurphy Mar 17, 2023

Choose a reason for hiding this comment

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

Good question, inside VSCode, both TS4.9 and TS5.0 show Node<Data> even without this annotation.
type-coverage is where the error appears
(correction, this is specific to TS5.0, see later comment)

unified/test/process.js:50:19: tree
unified/test/process.js:103:19: tree
unified/test/run.js:552:19: tree
unified/test/run.js:562:19: _
unified/test/use.js:255:19: node
2855 / 2860 99.82%

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like TS5 support in type-coverage is really new plantain-00/type-coverage#118
I'm double checking I have version v2.25.0 or higher locally now.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is version v2.25.0 ✅

Copy link
Member

Choose a reason for hiding this comment

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

They’re asking the community to report regressions. I think this one would be a most welcome issue upstream. :)

I would like to update to TypeScript 5, but unless we want to use any new TypeScript features, I’m not in a hurry to update. I’d rather wait for an upstream fix than adding workarounds.

Copy link
Member Author

@ChristianMurphy ChristianMurphy Mar 17, 2023

Choose a reason for hiding this comment

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

Hmm, this is an interesting one, when I try to replicate the issue in the TS Playground, it works again.
(playground, playground 2 in either disable noUnusedLocals)

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 would like to update to TypeScript 5, but unless we want to use any new TypeScript features, I’m not in a hurry to update. I’d rather wait for an upstream fix than adding workarounds.

💯 agree

Copy link
Member Author

Choose a reason for hiding this comment

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

Update, as of TypeScript 5.1.6 and Type Coverage 2.26.0, it is still an any type.
typescript does not throw anymore, but type-coverage does.

unified/test/process.js:50:19: tree
2865 / 2866 99.96%
The type coverage rate(99.96%) is lower than the target(100%).

Copy link
Member

Choose a reason for hiding this comment

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

@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (4a94722) 100.00% compared to head (c08667b) 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #216   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          596       596           
=========================================
  Hits           596       596           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ChristianMurphy ChristianMurphy added the ☂️ area/types This affects typings label Mar 17, 2023
@wooorm
Copy link
Member

wooorm commented Mar 18, 2023

So this can be merged, and then TS may improve some things later in their project?

@ChristianMurphy
Copy link
Member Author

So this can be merged, and then TS may improve some things later in their project?

That could be an option, thoughts @remcohaszing?

@remcohaszing
Copy link
Member

Still this: https://github.com/unifiedjs/unified/pull/216/files#r1140496841

Updating now doesn't give us any benefits. It only means we need to apply a workaround for a regression. I'd rather delay until this regression is fixed upstream, or TypeScript adds new features that do benefit unified.

This is just a dev dependency. It doesn't matter for users.

@wooorm
Copy link
Member

wooorm commented Aug 9, 2023

What’s the status of this @ChristianMurphy?

@wooorm wooorm changed the title TypeScript 5 Update typescript Aug 9, 2023
@wooorm wooorm merged commit ffc146c into unifiedjs:main Aug 9, 2023
@wooorm wooorm added the 💪 phase/solved Post is done label Aug 9, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Aug 9, 2023
@ChristianMurphy ChristianMurphy deleted the typescript-5 branch August 9, 2023 13:38
@ChristianMurphy
Copy link
Member Author

What’s the status of this @ChristianMurphy?

Merged, apparently 🙂

wooorm added a commit that referenced this pull request Aug 9, 2023
Maybe updating `types/unist` will solve it?

Related-to: #216.
kodiakhq bot referenced this pull request in X-oss-byte/Nextjs Oct 16, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [unified](https://unifiedjs.com) ([source](https://togithub.com/unifiedjs/unified)) | [`8.4.2` -> `11.0.3`](https://renovatebot.com/diffs/npm/unified/8.4.2/11.0.3) | [![age](https://developer.mend.io/api/mc/badges/age/npm/unified/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/unified/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/unified/8.4.2/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/unified/8.4.2/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>unifiedjs/unified (unified)</summary>

### [`v11.0.3`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.3)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.2...11.0.3)

##### Fix

-   [`8dee2ab`](https://togithub.com/unifiedjs/unified/commit/8dee2ab) Fix support for functions in data

**Full Changelog**: unifiedjs/unified@11.0.2...11.0.3

### [`v11.0.2`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.2)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.1...11.0.2)

-   [`cea788b`](https://togithub.com/unifiedjs/unified/commit/cea788b) Fix type of settings if nothing is registered yet

**Full Changelog**: unifiedjs/unified@11.0.1...11.0.2

### [`v11.0.1`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.0...11.0.1)

-   [`d1a915d`](https://togithub.com/unifiedjs/unified/commit/d1a915d) Fix incorrect type of `settings` in presets

**Full Changelog**: unifiedjs/unified@11.0.0...11.0.1

### [`v11.0.0`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.1.2...11.0.0)

##### Change

-   [`baf80b2`](https://togithub.com/unifiedjs/unified/commit/baf80b2) Change to require Node.js 16
    **migrate**: update too
-   [`dd9834a`](https://togithub.com/unifiedjs/unified/commit/dd9834a) Update `@types/unist`
    **migrate**: update too
-   [`620ccf9`](https://togithub.com/unifiedjs/unified/commit/620ccf9) Update [`vfile`](https://togithub.com/vfile/vfile/releases/tag/6.0.0)
    **migrate**: update too

##### Change (unlikey to affect you)

-   [`a44db46`](https://togithub.com/unifiedjs/unified/commit/a44db46) Add `Data`, `Settings` types to augment shared data
    **migrate**: if you deal with data, type it, see commit for info
-   [`fb49556`](https://togithub.com/unifiedjs/unified/commit/fb49556) Change to replace `Buffer` with `Uint8Array`
    **migrate**: you’re probably fine unless you use weird encodings, see commit for details if so
-   [`f3e71a8`](https://togithub.com/unifiedjs/unified/commit/f3e71a8) Remove `Attacher` type
    **migrate**: use `Plugin` instead
-   [`cc53bb6`](https://togithub.com/unifiedjs/unified/commit/cc53bb6) Remove `FrozenProcessor` type
    **migrate**: use `Processor` instead
-   [`1aa3494`](https://togithub.com/unifiedjs/unified/commit/1aa3494) Change to yield `undefined`, not `null`
    **migrate**: expect `undefined`
-   [`932c140`](https://togithub.com/unifiedjs/unified/commit/932c140) Change to use `exports`
    **migrate**: don’t use private APIs
-   [`8e57478`](https://togithub.com/unifiedjs/unified/commit/8e57478) Remove support for classes as compilers, parsers
    **migrate**: if you love classes, see commit message
-   [`4676814`](https://togithub.com/unifiedjs/unified/commit/4676814) Remove support for compilers returning nullish
    **migrate**: nobody did that
-   [`807ffb9`](https://togithub.com/unifiedjs/unified/commit/807ffb9) Add improved types
    **migrate**: it’s probably just better if anything changed at all
-   [`b35afe0`](https://togithub.com/unifiedjs/unified/commit/b35afe0) Add useful error on empty presets
    by [@&#8203;wooorm](https://togithub.com/wooorm) in [https://github.com/unifiedjs/unified/pull/202](https://togithub.com/unifiedjs/unified/pull/202)
-   [`6f068a0`](https://togithub.com/unifiedjs/unified/commit/6f068a0) Fix to deep clone preset settings
-   [`56ee288`](https://togithub.com/unifiedjs/unified/commit/56ee288) Fix non-first parameter merging when reconfiguring plugins

##### Misc

-   [`e58b095`](https://togithub.com/unifiedjs/unified/commit/e58b095) [`ad06700`](https://togithub.com/unifiedjs/unified/commit/ad06700) [`40f0329`](https://togithub.com/unifiedjs/unified/commit/40f0329) Refactor code-style
-   [`ffc146c`](https://togithub.com/unifiedjs/unified/commit/ffc146c) Update `typescript`
    by [@&#8203;ChristianMurphy](https://togithub.com/ChristianMurphy) in [https://github.com/unifiedjs/unified/pull/216](https://togithub.com/unifiedjs/unified/pull/216)
-   [`7148746`](https://togithub.com/unifiedjs/unified/commit/7148746) [`144eec0`](https://togithub.com/unifiedjs/unified/commit/144eec0) [`2d95451`](https://togithub.com/unifiedjs/unified/commit/2d95451) Add improved docs
-   [`afb704a`](https://togithub.com/unifiedjs/unified/commit/afb704a) Fix some typos
    by [@&#8203;ChristianMurphy](https://togithub.com/ChristianMurphy) in [https://github.com/unifiedjs/unified/pull/225](https://togithub.com/unifiedjs/unified/pull/225)
-   [`2aa15ea`](https://togithub.com/unifiedjs/unified/commit/2aa15ea) Refactor types
-   [`a06537c`](https://togithub.com/unifiedjs/unified/commit/a06537c) Add sponsor

**Full Changelog**: unifiedjs/unified@10.1.2...11.0.0

### [`v10.1.2`](https://togithub.com/unifiedjs/unified/releases/tag/10.1.2)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.1.1...10.1.2)

-   [`dc85d21`](https://togithub.com/unifiedjs/unified/commit/dc85d21) Fix typo
    by [@&#8203;jablko](https://togithub.com/jablko) in [https://github.com/unifiedjs/unified/pull/185](https://togithub.com/unifiedjs/unified/pull/185)

**Full Changelog**: unifiedjs/unified@10.1.1...10.1.2

### [`v10.1.1`](https://togithub.com/unifiedjs/unified/releases/tag/10.1.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.1.0...10.1.1)

-   [`6b060c2`](https://togithub.com/unifiedjs/unified/commit/6b060c2) Fix type of `run` signature
    by [@&#8203;alvinleung1996](https://togithub.com/alvinleung1996) in [https://github.com/unifiedjs/unified/pull/174](https://togithub.com/unifiedjs/unified/pull/174)

**Full Changelog**: unifiedjs/unified@10.1.0...10.1.1

### [`v10.1.0`](https://togithub.com/unifiedjs/unified/releases/tag/10.1.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.0.1...10.1.0)

-   [`134ecad`](https://togithub.com/unifiedjs/unified/commit/134ecad) Add plugin input/output type parameters

### [`v10.0.1`](https://togithub.com/unifiedjs/unified/releases/tag/10.0.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.0.0...10.0.1)

-   [`591b0c0`](https://togithub.com/unifiedjs/unified/commit/591b0c0) Fix types to support `void` async transformers

### [`v10.0.0`](https://togithub.com/unifiedjs/unified/releases/tag/10.0.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.2.2...10.0.0)

##### Breaking

-   [`dc46bc5`](https://togithub.com/unifiedjs/unified/commit/dc46bc5) Use ESM and update `vfile`
    -   Change:

        ```js
        // from cjs import
        var unified = require('unified')

        // to esm import
        import {unified} from 'unified'
        ```

        Learn [more about ESM in this guide](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
    -   **Breaking**: this updates `vfile`, which importantly renames ~~`vfile.contents`~~ to `vfile.value`. See [`vfile@5`](https://togithub.com/vfile/vfile/releases/tag/5.0.0)
    -   Inconsequential: this updates `trough`, which removes support for Promise-like objects returned from plugins, in favor of only support actual promises. To update, instead of returning an object with a `then` function, return and *actual* promise

##### Types

-   [`b3e2464`](https://togithub.com/unifiedjs/unified/commit/b3e2464) Rewrite types
    -   Removed the type parameter `P` for processor settings
    -   Use `any[]` instead of `[Record<string, unknown>?]` for the default plugin type parameters
-   [`45eb72e`](https://togithub.com/unifiedjs/unified/commit/45eb72e) Update types for ESM
-   [`2c7ba99`](https://togithub.com/unifiedjs/unified/commit/2c7ba99) [`8eda349`](https://togithub.com/unifiedjs/unified/commit/8eda349) Add explicit dependency on `@types/unist`
-   [`0e8f611`](https://togithub.com/unifiedjs/unified/commit/0e8f611) Remove typescript@3 legacy support
-   [`350ed9d`](https://togithub.com/unifiedjs/unified/commit/350ed9d) Fix `next` in types of transformer signature
-   [`b22bf8e`](https://togithub.com/unifiedjs/unified/commit/b22bf8e) Add support for buffer, other return values
-   [`4bfd6c8`](https://togithub.com/unifiedjs/unified/commit/4bfd6c8) [`b8fe5ec`](https://togithub.com/unifiedjs/unified/commit/b8fe5ec) [`6ef3933`](https://togithub.com/unifiedjs/unified/commit/6ef3933) Add support for boolean plugin options

##### Project

-   [`88374fc`](https://togithub.com/unifiedjs/unified/commit/88374fc) Add `esast` to list of syntax trees
-   [`a6ff3c1`](https://togithub.com/unifiedjs/unified/commit/a6ff3c1) Fix links
-   [`ee6ee47`](https://togithub.com/unifiedjs/unified/commit/ee6ee47) Update examples in `readme.md`
-   [`32abf7c`](https://togithub.com/unifiedjs/unified/commit/32abf7c) [`60de570`](https://togithub.com/unifiedjs/unified/commit/60de570) [`115898a`](https://togithub.com/unifiedjs/unified/commit/115898a) Refactor code style

### [`v9.2.2`](https://togithub.com/unifiedjs/unified/releases/tag/9.2.2)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.2.1...9.2.2)

-   [`bc50a01`](https://togithub.com/unifiedjs/unified/commit/bc50a01) Fix to set `vfile.value` if a vfile@5 is given

### [`v9.2.1`](https://togithub.com/unifiedjs/unified/releases/tag/9.2.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.2.0...9.2.1)

-   [`fe51be2`](https://togithub.com/unifiedjs/unified/commit/fe51be2) Fix mutating options
-   [`8f135d0`](https://togithub.com/unifiedjs/unified/commit/8f135d0) Refactor to improve bundle size
-   [`ad12369`](https://togithub.com/unifiedjs/unified/commit/ad12369) Remove outdated description of compile results

### [`v9.2.0`](https://togithub.com/unifiedjs/unified/releases/tag/9.2.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.1.0...9.2.0)

-   [`7fc4271`](https://togithub.com/unifiedjs/unified/commit/7fc4271) Add variadic tuple types for plugin tuple

### [`v9.1.0`](https://togithub.com/unifiedjs/unified/releases/tag/9.1.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.0.0...9.1.0)

-   [`56fdba4`](https://togithub.com/unifiedjs/unified/commit/56fdba4) Add `FrozenProcessor` interface to types

### [`v9.0.0`](https://togithub.com/unifiedjs/unified/releases/tag/9.0.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/8.4.2...9.0.0)

-   [`c3ba172`](https://togithub.com/unifiedjs/unified/commit/c3ba172) Set `file.result` when processing to non-text
    (**breaking**, if you’re using `.process` or `.processSync` with a compiler that returns an object, then those results were available at ~~`file.contents`~~ and are now at `file.result`)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/X-oss-byte/Nextjs).
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
Development

Successfully merging this pull request may close these issues.

4 participants