Skip to content

Conversation

sandersn
Copy link

@sandersn sandersn commented Jul 24, 2025

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

I am testing Typescript 7's JS support, which I've largely rewritten during the switch to Go. The new code processes tags by converting them into synthetic nodes just after parsing their host node. For unified, that means that @template tags can't be shared between multiple @overload tags like before.

This PR also has to convert function declarations with @type on them to variables initialised with a function expression. TS7 doesn't currently support this feature on function declarations--but both unified and svelte use this feature a lot, so I think we'll need to add it before TS7's JS features are ready. At that point the shuffling of functions won't be needed anymore and this PR will be very small.

In addition, microsoft/typescript-go#1444 makes it possible to have rest parameters in @overload, and is needed for this change to work in TS7, so it won't compile with the nightly until that PR is merged.
Edit: it will be available in the 2025-07-25 nightly.

Because TS7 is quite a way off, I don't know whether you'll want to take this PR. I created it to see how hard it would be to update popular JS code that uses TS for checking.

I am testing Typescript 7's JS support, which I've largely rewritten
during the switch to Go. The new code processes tags by converting them
into synthetic nodes just after parsing their host node. For unified,
that means that `@template` tags can't be shared between multiple
`@overload` tags like before.

This PR also has to convert function declarations with `@type` on them
to variables initialised with a function expression. TS7 doesn't
currently support this feature on function declarations--but both unified and
svelte use this feature a lot, so I think we'll need to add it before
TS7's JS features are ready. At that point the shuffling of functions in
the test files won't be needed anymore.

In addition, microsoft/typescript-go#1444 makes
it possible to have rest parameters in `@overload`, and is needed for
this change to work in TS7, so it won't compile with the nightly until
that PR is merged.

Because TS7 is quite a way off, I don't know whether you'll want to take this PR. I created it to see how hard it would be to update popular JS code that uses TS for checking.
@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label Jul 24, 2025

This comment has been minimized.

@github-actions github-actions bot added 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jul 24, 2025
Copy link

codecov bot commented Jul 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b69689b) to head (c9b3870).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #264   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines         1364      1364           
=========================================
  Hits          1364      1364           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sandersn
Copy link
Author

I reverted the function->const move because I couldn't get it to compile in TS5 and I've decided to add whole-type annotated functions in TS7, so that change won't be needed.

@wooorm
Copy link
Member

wooorm commented Jul 26, 2025

Hi again!

Right, probably makes sense to have the @templates on the overloads! So that also works on TS5? And you do now recommend landing this PR for us?

If you are looking at userland code, you might as well also look at https://github.com/unifiedjs/unified/blob/main/script/fix-types.js 😉 It may be especially interesting because it also deals with rest parameters 🤔

@sandersn
Copy link
Author

Yes, I'd recommend this change everywhere. Shared template tags is a mistake that I've never fixed until TS7 gave me a chance to break JS backward compatibility.

@sandersn
Copy link
Author

re fix-types.js: it looks like it had to fix up rest parameters with | undefined pre-5.3 and with a postfix [] pre-5.5?

It sounds like I need to make sure that TS7 works with this type: @param {Parameters | [boolean]} rest for rest parameters that might look like ...rest. Is that correct? I hope so because I think that is its current state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤞 phase/open Post is being triaged manually
Development

Successfully merging this pull request may close these issues.

2 participants