-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
RFC: Remove I-prefix from TypeScript interfaces and types #10266
Comments
I am in favor of omitting the |
I don't mind the
|
number 3 is pretty valid as well. If we already have tools informing us of the cost of importing, we are making a major deviation from the OSS/TS standard for little reason. |
I still keep I'm not sure if it is worth the massive churn (including downstream) to change at this point. We could possibly export both but then that raises a 2nd question: do we then always export two versions for all new interfaces as well? |
Just coming back to this. I tried not using I prefixes and run into naming concerns a bunch. For example, we have To me I keep thinking of the prefix as a private indicator. It expresses intent; don't use this thing as a new'able resource. It is the type safety that typescript will strip out in a transpile step. But I think i'm swimming upstream here. |
I'm indifferent towards one approach or the other but definitely see the benefit of having consistent naming standards in our codebase. If we do decide to drop the I before interfaces and go with deprecated names I think this is as good a time as any to start thinking how long we're going to support deprecations. Will we delete deprecated props in the next release? Will we support these props in the next release and delete them the release after that? If we go with the second option, how do we differentiate props we deprecated in v-1 that we need to support vs props we deprecated in v-2 that we need to delete? |
@khmakoto I would propose that given there is an upgrade script for customers, and in my proposal a JSON file documenting all symbolic renames, we could use the JSON list as a "safe for removal" list on upgrade. As long as customers have a way to easily update their code, I think we can be more aggressive about cleanup. It's when it's a giant chore for them that we need to reserve major caution. That's my take, what do you think? |
@dzearing that sounds good to me, I think going forward having the least baggage possible is going to be a good thing. 😄 |
Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes. Still require assistance? Please, create a new issue with up-to date details. |
Overview
All existing interfaces and types in all v7 packages are currently prefixed with I. All interfaces and types in v0 packages are not. Let's choose one path.
Reasons for prefixing
IThing
could be implemented by aThing
. Without the prefix, you would need an alternative prefix or suffix to avoid the collision such asThingAPI
orThingInterface
, which leads to inconsistencies.If we choose to embrace I-prefix, we can avoid naming collisions but will need to cov
Reasons against prefixing
If we choose to abandon I-prefix, we need to propose naming guidance for when developers hit the classic
IFoo
interface vsFoo
implementation.Prior considerations
TypeScript thread here:
microsoft/TypeScript-Handbook#121
There are multiple customer complaints that the guidance has no principles or reasoning behind the decision other than it was deemed "an unnecessary relic of C# days". No guidance been provided in regards to naming conventions to deal with typing differentiation. Additionally the TypeScript team has mentioned not prefixing generic placeholders with
T
(e.g.function foo<TThing>(arg: TThing)
).Stack overflow article here:
https://stackoverflow.com/questions/31876947/confused-about-the-interface-and-class-coding-guidelines-for-typescript
Some clarifications offered:
IFoo
type and aFoo
implementation. That's "bad" becauseFoo
should be more specific.I
violates encapsulation of the type (changing from an interface to a type would then remove theI
right?) Our approach has been to prefix alltype
andinterface
names withI
, and treat them interchangeably.Proposed direction
For consistency with TypeScript conventions, we abandon I-prefix. This means that all interfaces would need to be renamed, with I-prefixed deprecated re-exports.
Example:
IColor
interface, orISize
type becomes:Once we settle, we will update the wiki here:
https://github.com/microsoft/fluentui/wiki/Coding-Style#prefix-interfaces-and-sometimes-types-with-i
Special considerations
There are many scenarios where removing the prefix creates a symbol collision. Naming is hard, and removing the prefix makes things harder, so we need to have strong guidance on improved type naming conventions to reduce inconsistencies.
IButton
ImperativeHandle
suffix. (ButtonImperativeHandle
)IButtonStyles
Type
suffix. (ButtonStylesType
)More examples of collisions in the codebase currently:
IExampleGroup
,IRefObject
,IRectangle
,IAppCustomizations
,IColorClassNames
,IAnimationStyles
,IAnimationVariables
,ICustomizations
,ISettings
,ISettingsFunction
,ICustomizerContext
,ISelection
,IDonutChart
,ILineChart
,IPieChart
,IStackedBarChart
,IVerticalBarChart
,IDatePickerStyles
,IAppDefinition
,IAccordion
,IButtonSlots
,IButtonTokens
,IButtonStyles
,IChicletCard
,ICollapsibleSection
,IFloatingSuggestions
,IMicroFeedback
,IMicroFeedbackTokens
,IMicroFeedbackStyles
,IPersonaCoinStyles
,ISelectedItemsList
,ISliderStyles
,IToggleTokens
,IToggleStyles
,IScrollContainer
,IBreadcrumbStyles
,IButtonStyles
,ICalloutContentStyles
,ICheckStyles
,ICheckboxStyles
,IColorPickerStyles
,IComboBoxStyles
,ICommandBarStyles
,IContextualMenuItem
,IContextualMenuStyles
,IDatePickerStyles
,IDetailsColumnStyles
,IDetailsHeaderStyles
,IDetailsListStyles
,IDetailsRowStyles
,IDetailsRowCheckStyles
,IDialogContentStyles
,IDialogFooterStyles
,IDocumentCardStyles
,IDropdown
,IDropdownStyles
,IBaseExtendedPicker
,IFacepileStyles
,IGroupHeaderStyles
,IExpandingCard
,IExpandingCardStyles
,IImage
,IKeytip
,ILabelStyles
,ILinkStyles
,IPage
,IMessageBarStyles
,IModalStyles
,INavStyles
,IOverlayStyles
,IPanelStyles
,IPersonaStyles
,IPersonaCoinStyles
,IBasePicker
,IBasePickerStyles
,IPivotStyles
,IProgressIndicatorStyles
,IRatingStyles
,IScrollablePaneContext
,ISearchBoxStyles
,IBaseSelectedItemsList
,ISeparator
,ISliderStyles
,ISpinButtonStyles
,IColorPickerGridCellStyles
,ITeachingBubbleStyles
,ITextStyles
,ITextFieldStyles
,IToggleStyles
,IViewport
,IDragDropHelper
,IPosition
,ISelectionZone
,ICard
,ICardTokens
,ICardStyles
,IActionableSlots
,IActionable
,IActionableTokens
,IActionableStyles
,IMenuButtonSlots
,IMenuButton
,IMenuButtonTokens
,IMenuButtonStyles
,ISplitButtonSlots
,ISplitButton
,ISplitButtonTokens
,ISplitButtonStyles
,IVerticalPersonaStyles
,IVerticalPersonaTokens
,ISelectedPeopleList
,IExampleGroup
,IChoiceGroupOptionStyles
,IColorRectangleStyles
,IColorSliderStyles
,IPlainCard
,IPlainCardStyles
,ISuggestions
,ISuggestionsStyles
,ITagItemStyles
,IStackItemStyles
,ICardItem
,ICardItemTokens
,ICardItemStyles
,ICardSection
,ICardSectionTokens
,ICardSectionStyles
Conversion plan for codebase
A
ts-morph
script would manage the renames in bulk. The process would be that for each interface identified that matches an I prefix, apply a rename across the repo. This applies to bothinterface
andtype
definitions. The old name would also be exported as deprecated to avoid breaking changes:Before:
After:
Conversion plan for customers
An
upgrade-fluentui
command would be provided for customers as an executable node script upon install. This script would apply all symbolic renames defined in a JSON file to the customer's source files when executed.The JSON file would define all symbolic renames resulting from the automated conversion above.
When the user runs
upgrade-fluentui
in their repo, these changes would be applied, as an example:Before (src/**/App.tsx)
After:
This process would need to be documented, and ideally mentioned when yarn installing, similar to how some npm libraries have postinstall steps that warn about out of date dependencies.
The text was updated successfully, but these errors were encountered: