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

feat: TypeScript 3.9 upgrade #7324

Closed
wants to merge 15 commits into from

Conversation

ivanhofer
Copy link
Contributor

@ivanhofer ivanhofer commented Feb 28, 2022

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with [feat], [fix], [chore], or [docs].
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

The content of this PR originally belonged to #7224 that introduces a "more complex" TypeScript type.

TLDR: the changes of this PR are not required for #7224 but would improve the Svelte codebase.
(and I think I have found one or the oder "bug" while adding types)

  1. In order to ensure the type definition stays intact I wanted to introduce "type-tests", which are tests that just look at the type-definitions and don't test the actual implementation.
  2. But this requires a minimum TypeScript version of 3.9.x
  3. and the strict Compiler option set to true`
  4. because of missing type definitions inside some core functions the type-tests fail
  5. so we need to also add types for these core functions

There are still some type definitions missing and a few open TODOs.
I have opened this PR as a draft to be able to sl´plit the original PR.

Note: I have created a type called TODO which marks parts that need a deeper look either because the type-definitions need to be improved or it currently is unclear (to me) what the actual type should be.

Step 4 + 5 could be eliminated if the type definitions of createEventDispatcher are moved to a separate file.

@Conduitry
Copy link
Member

Would we be breaking the published types by doing this for people who haven't upgraded TS in their projects to 3.9?

@ivanhofer
Copy link
Contributor Author

@Conduitry if the type definitions exposed by the Svelte repository (stores etc.) would only contain valid TypeScript 3.7 syntax, noone would be affected. Internal functions could still benefit from a few new typechecking features introduced in version

Since there are no real big changes made to the syntax, the risk is tolerable in my opinion.
Maybe the import type syntax could become an issue.

@baseballyama
Copy link
Member

According to latest package-lock.json, already we are using 3.9.10.
https://github.com/sveltejs/svelte/blob/master/package-lock.json#L9038-L9043

Therefore I think we can update this now without regarding it as breaking change.

@dummdidumm
Copy link
Member

I think we bumped it at some point for something internal and said "we gotta be careful not to introduce anything that's not 3.x compatible which is the minimum version we actually support. Not sure what the real minimum version is though. But if this change only changes things internally but not externally, yes we could merge it.

@benmccann
Copy link
Member

We're going to be doing a Svelte 4 release soon with some housekeeping. We might as well upgrade to the latest TypeScript as part of it if you'd like to update this

@vercel
Copy link

vercel bot commented Feb 22, 2023

@ivanhofer is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor Author

@ivanhofer ivanhofer left a comment

Choose a reason for hiding this comment

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

@benmccann I'm done with the merge.

There are some TODO's left where I would need some help.

@@ -50,6 +50,7 @@ export function invalidate(renderer: Renderer, scope: Scope, node: Node, names:
const extra_args = tail.map(variable => get_invalidated(variable)).filter(Boolean);

if (is_store_value) {
// TODO: check why there are 4 parameters, but `set_store_value` only expects 3
return x`@set_store_value(${head.name.slice(1)}, ${node}, ${head.name}, ${extra_args})`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can someone please confirm that it is wrong to pass 4 arguments?

if (store == null) {
return noop;
}
const unsub = store.subscribe(...callbacks);
// TODO: `store` does not accept an array of callbacks
const unsub: any = store.subscribe(...(callbacks as [any]));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand what happens here. Can someone please help?

component.$$.on_destroy.push(subscribe(store, callback));
}

export function create_slot(definition, ctx, $$scope, fn) {
// TODO: find out what types are expected here instead of using `any` everywhere
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please help!

// 1. should be improved or
// 2. where casting is needed in order to satisfy TypeScript
// a deeper look at these parts is needed to check if they can be replaced with a normal cast or if they currently contain a potential bug
type TODO<T = any> = T
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most things were typed after enabling TypeScript's strict mode.
Those TODO casts are not always needed currently, but I think enabling strict mode for the future makes sense.

@dummdidumm dummdidumm added this to the 4.x milestone Mar 2, 2023
@benmccann benmccann changed the base branch from master to version-4 April 11, 2023 21:07
@dummdidumm
Copy link
Member

Closing in favor of #8488 - I'll integrate the commented-out tests over to #7224

@dummdidumm dummdidumm closed this Apr 12, 2023
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.

None yet

5 participants