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 to TS5 #1240

Merged
merged 10 commits into from
Aug 23, 2023
Merged

Update to TS5 #1240

merged 10 commits into from
Aug 23, 2023

Conversation

frandiox
Copy link
Contributor

Closes #1175
Continues #778 and fixes the issues found there.

@frandiox frandiox requested a review from a team August 17, 2023 13:22
@frandiox frandiox mentioned this pull request Aug 17, 2023
Comment on lines -139 to 140
// ts-expect-error should error because 'measurement' isn't an accepted prop
// unforutnately it does error. There's something I'm missing here
// @ts-expect-error should error because 'measurement' isn't an accepted prop
render(<ProductPrice data={getProduct()} measurement="" />);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@frehner do you remember about this comment? I'm somewhat confused after reading it.

The measurement is not shown in the docs so... TS should show error, right?
The TS comment was missing an @ and I've added it because it is (at least now) showing error. I've enabled this unit test as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

From the comment, it seems like the situation was: I was expecting it to error, but it wasn't erroring for some reason. But now with the newest update, it seems TS figured out that it should be erroring (as was expected), so your change seems correct.

If that makes sense? haha. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

// unforutnately it does error. There's something I'm missing here

I probably meant to write

// unforutnately it doesn't error. There's something I'm missing here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah I see, thanks for checking! 🙌

Comment on lines +22 to +27
(AsType extends keyof React.JSX.IntrinsicElements
? Omit<
React.ComponentPropsWithoutRef<AsType>,
keyof CustomBaseButtonProps<AsType>
>
: React.ComponentPropsWithoutRef<AsType>);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI It looks like the important part here is the actual discrimination. Apparently, TS5 is more strict. The second part (the "else") could be {} (empty object) or even the same Omit<...> thing and would still work.

Comment on lines 7 to 13
Update to TypeScript 5. If you have `typescript` as a dev dependency in your app, change its version as follows:

```diff
"devDependencies": {
...
- "typescript": "^4.9.5",
+ "typescript": "^5.1.6",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if the type fixes are still compatible with TS 4? Is moving to TS 5 a requirement if we merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it works in TS4 as well. These are just generic fixes we needed but TS4 was not catching.
For example, see a prop like measurement should throw a TS error but it wasn't doing it before (it does now): https://github.com/Shopify/hydrogen/pull/1240/files#r1297221747

TS5 is not a requirement but, since the CLI installs it for tarnspiling stuff, it's better to update projects and avoid dependency duplication.

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've reworded the changeset to make this more clear and also explained how to change the TS version in VSCode 👍

Comment on lines -334 to -336
TYPE_NAVIGATE: 1,
TYPE_RELOAD: 2,
TYPE_BACK_FORWARD: 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't change these values - These are code mapping for PerformaneNavigation api

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigation#instance_properties

Copy link
Contributor Author

@frandiox frandiox Aug 18, 2023

Choose a reason for hiding this comment

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

Hmm... this is just a unit test so I guess I can just ts-ignore my way but even that MDN link says it should start with 0, no? 🤔 -- Or am I reading it wrong?

The TS types are also showing 0,1,2 instead of 1,2,3:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh .. I guess I had it wrong this whole time (facepalm)

@frandiox frandiox merged commit 06516ee into 2023-07 Aug 23, 2023
@frandiox frandiox deleted the fd-ts5-v2 branch August 23, 2023 07:42
This was referenced Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support TypeScript 5
4 participants