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

[lab] Migrate Timeline to TypeScript #23242

Merged
merged 2 commits into from
Nov 2, 2020

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Oct 25, 2020

I have extracted some of the changes from #22692 and completed the missing part to allow migrating the Timeline component to TypeScript. I have used the Timeline as it's simple enough to test the direction. As far as I know, this would make the very first component written in TypeScript.

Related to #15984

@mui-pr-bot
Copy link

mui-pr-bot commented Oct 25, 2020

Details of bundle changes

Generated by 🚫 dangerJS against 7d90cf7

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 29, 2020
@oliviertassinari oliviertassinari force-pushed the lab-host-typescript branch 3 times, most recently from 372dd52 to b312efc Compare October 30, 2020 00:11
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 30, 2020
@oliviertassinari oliviertassinari force-pushed the lab-host-typescript branch 2 times, most recently from 0340f74 to a3f2f79 Compare October 30, 2020 00:39
@oliviertassinari oliviertassinari added core Infrastructure work going on behind the scenes typescript labels Oct 30, 2020
@oliviertassinari oliviertassinari marked this pull request as ready for review October 30, 2020 10:41
/** Styles applied to the root element if `align="alternate"`. */
alignAlternate?: string;
};
ref?: React.Ref<HTMLUListElement>;
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 couldn't use:

Suggested change
ref?: React.Ref<HTMLUListElement>;
ref?: React.Ref<unknow>;

which is the default

Suggested change
ref?: React.Ref<HTMLUListElement>;

it fails with a "can't assign unknown to HTMLUListElement" error message if I don't set the correct type.

Copy link
Member

Choose a reason for hiding this comment

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

The outer interface is more important here. I've gone through length to find the best possible type for ref so we shouldn't revert this partially just because the inner types are annoying. This is part of why I have problems with migrating to typescript: it might regress the DX for library users.

Copy link
Member

Choose a reason for hiding this comment

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

microsoft/TypeScript#30748 and #15199 for more context

Copy link
Member Author

@oliviertassinari oliviertassinari Oct 30, 2020

Choose a reason for hiding this comment

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

Ok, so we can simply:

// @ts-expected-error TypeScript bug, need to keep unknown for DX?

I like that :) (cc @dtassone ;))

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't say you can do anything "simply" in TypeScripts' JSX domain 😀 It's just bit unfortunate that this pattern of assigning and reading refs isn't supported by TS because we don't have control over covariance vs contravariance in function calls. But yes, you probably can @ts-expect-error assignments of less specific refs to the ref prop.

docs/scripts/buildApi.ts Outdated Show resolved Hide resolved
packages/material-ui-lab/src/Timeline/Timeline.tsx Outdated Show resolved Hide resolved
<TimelineContext.Provider value={{ align }}>
<ul
className={clsx(
classes!.root,
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'm not super happy about this one, but it seems to be a reasonable tradeoff.

Copy link
Member

Choose a reason for hiding this comment

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

You're only typing the outer props i.e. the props a user can pass in but these are not the same props the component actually receives due to higher-order components.

We need to come up with a robust approach once we're starting to switch to emotion so that we don't degrade user types. Not important for this PR but v5 release.

Copy link
Member Author

Choose a reason for hiding this comment

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

@eps1lon Agree, the main motivation for opening this pull request was to help with #22692.

@oliviertassinari oliviertassinari merged commit 12cf9ae into mui:next Nov 2, 2020
@oliviertassinari oliviertassinari deleted the lab-host-typescript branch November 2, 2020 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants