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

[typings] Switch tabIndex from string type to number | string #8115

Merged
merged 2 commits into from Sep 9, 2017
Merged

[typings] Switch tabIndex from string type to number | string #8115

merged 2 commits into from Sep 9, 2017

Conversation

xaviergonz
Copy link
Contributor

Basically this fixes an inconsistency where some tabIndex props where numbers in some components and others were mistakenly typed as string (since the tabIndex type in the react official types is number, not string.

@oliviertassinari
Copy link
Member

Looking at JedWatson/react-select#1595 I think that we should allow both string and integer type but using integer internally in the lib.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

I think that we should be updating the typescript definition too.

@oliviertassinari oliviertassinari added flow typescript PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Sep 9, 2017
@oliviertassinari oliviertassinari changed the title switching tabIndex from string type in some components to number [typings] Switch tabIndex from string type to number Sep 9, 2017
@xaviergonz
Copy link
Contributor Author

so should I change them all to be string | number then?
Btw, are you referring to ts type defs? I changed those too

@oliviertassinari
Copy link
Member

My bad, the typescript are already in sync 👍

@oliviertassinari
Copy link
Member

Yes, I think that it would be better with string | number :).

@xaviergonz xaviergonz changed the title [typings] Switch tabIndex from string type to number [typings] Switch tabIndex from string type to number | string Sep 9, 2017
@oliviertassinari oliviertassinari removed the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Sep 9, 2017
@oliviertassinari
Copy link
Member

@xaviergonz Great!

@oliviertassinari oliviertassinari merged commit 2c14f49 into mui:v1-beta Sep 9, 2017
@xaviergonz
Copy link
Contributor Author

xaviergonz commented Sep 10, 2017

@oliviertassinari The latest release doesn't compile with TS due to this bug :(

node_modules/material-ui-next/Chip/Chip.d.ts(4,18): error TS2430: Interface 'ChipProps' incorrectly extends interface 'HTMLAttributes<HTMLDivElement>'.
failed with code 2
Types of property 'tabIndex' are incompatible.
Type 'string | number | undefined' is not assignable to type 'number | undefined'.
Type 'string' is not assignable to type 'number | undefined'.

basically it is complaining that the react type (number | undefined) and the new one (number | string | undefined) are not compatible

Should I change it back to number | undefined for that particular case or them all?

Another possibility would be to hand pick properties from HTMLAttributes that might be needed, but I don't know which those would be.

@oliviertassinari
Copy link
Member

@xaviergonz I would rather follow React.HTMLAttributes<HTMLDivElement> typing for typescript. But isn't React.HTMLAttributes<HTMLDivElement> typing wrong?

@xaviergonz
Copy link
Contributor Author

xaviergonz commented Sep 10, 2017

I don't see how they would be, they are the official ones made by react guys. IMHO it is better to use a number, since actually tabIndex has to be a number (even when transformed in the end internally to a string attribute).

I guess they did it because that way you cannot mistype it as tabIndex="hello world" (which with material-ui right now is accepted but wrong), but instead have to type it as tabIndex={1234}

@xaviergonz
Copy link
Contributor Author

Also it is more natural for TS users, since we are used to do this (due to react official typings):
<div tabIndex={1234}/> since <div tabIndex="1234"/> gives you a type warning

@oliviertassinari
Copy link
Member

The following change for the typescript files should fix it then :)

-  tabIndex?: number | string;
+  tabIndex?: number;

@xaviergonz
Copy link
Contributor Author

I'll change them then on a new pull request :)

@xaviergonz xaviergonz deleted the tabIndex-to-number branch September 10, 2017 12:14
@oliviertassinari
Copy link
Member

Does it require a new release? If it does, I will wait a day or two to collect more feedback.

@xaviergonz
Copy link
Contributor Author

It would for TS users or they get compilation errors

@wcandillon
Copy link
Contributor

@oliviertassinari I would like a release for this fix please 🙋🏼‍♂️

@evolify
Copy link

evolify commented Sep 13, 2017

Me too, the same problem when use typescript.

@oliviertassinari
Copy link
Member

I will cut a release this evening.

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

4 participants