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

[Feature]: enforce explicit public API annotations via linter #33662

Open
1 task done
Hotell opened this issue Jan 15, 2025 · 0 comments
Open
1 task done

[Feature]: enforce explicit public API annotations via linter #33662

Hotell opened this issue Jan 15, 2025 · 0 comments

Comments

@Hotell
Copy link
Contributor

Hotell commented Jan 15, 2025

Area

React Components (@fluentui/react-components)

Describe the feature that you would like added

ATM our public APIs rely on TypeScript inference.

Example:

// Source
export const FluentProvider = React.forwardRef<HTMLElement, FluentProviderProps>((props, ref) => { ... }

⬇️ tsc emit ⬇️

// Emit
export declare const FluentProvider: React_2.ForwardRefExoticComponent<Omit<ComponentProps<FluentProviderSlots>, "dir"> & {
    applyStylesToPortals?: boolean | undefined;
    customStyleHooks_unstable?: Partial<{
        useAccordionHeaderStyles_unstable: (state: unknown) => void;
        useAccordionItemStyles_unstable: (state: unknown) => void;
        useAccordionPanelStyles_unstable: (state: unknown) => void;
        useAccordionStyles_unstable: (state: unknown) => void;
        useAvatarStyles_unstable: (state: unknown) => void;
        useAvatarGroupStyles_unstable: (state: unknown) => void;
        useAvatarGroupItemStyles_unstable: (state: unknown) => void;
        useAvatarGroupPopoverStyles_unstable: (state: unknown) => void;
        useBadgeStyles_unstable: (state: unknown) => void;
        useCounterBadgeStyles_unstable: (state: unknown) => void;
        useCardHeaderStyles_unstable: (state: unknown) => void;
        useCardStyles_unstable: (state: unknown) => void;
        useCardFooterStyles_unstable: (state: unknown) => void;
}>
}

This introduces various drawbacks:

  • when TSC and API-Extractor emit changes during migration to new versions it affects every v9 package
  • rolluped index.d.ts files are becoming bigger as inferred types are usually exapnded, if TSC cannot find proper type alias
  • significant perf impact on emitting .d.ts

The ask here is to mitigate these drawbacks

Solution proposal:

we can enforce these behaviours via existing lint rules

After that is implemented and setup - we can enable --isolatedDeclarations tsc emit that is also supported by swc cli (via jsc.experimental.emitIsolatedDts )

  • both js and d.ts emitted by 1 tool 💪
// Source
- export const FluentProvider = React.forwardRef<HTMLElement, FluentProviderProps>((props, ref) => { ... }
+ export const FluentProvider: ForwardRefComponent<FluentProviderProps> = React.forwardRef((props, ref) => {}

⬇️ tsc emit ⬇️

// Emit
- export declare const FluentProvider: React_2.ForwardRefExoticComponent<Omit<ComponentProps<FluentProviderSlots>, "dir"> & {
+ export declare const FluentProvider: Omit<ComponentProps<FluentProviderSlots>, 'dir'> & {
    applyStylesToPortals?: boolean | undefined;
+  customStyleHooks_unstable?: FluentProviderCustomStyleHooks;
-   customStyleHooks_unstable?: Partial<{
-       useAccordionHeaderStyles_unstable: (state: unknown) => void;
-        useAccordionItemStyles_unstable: (state: unknown) => void;
-        useAccordionPanelStyles_unstable: (state: unknown) => void;
-        useAccordionStyles_unstable: (state: unknown) => void;
-        useAvatarStyles_unstable: (state: unknown) => void;
-        useAvatarGroupStyles_unstable: (state: unknown) => void;
-        useAvatarGroupItemStyles_unstable: (state: unknown) => void;
-        useAvatarGroupPopoverStyles_unstable: (state: unknown) => void;
-        useBadgeStyles_unstable: (state: unknown) => void;
-        useCounterBadgeStyles_unstable: (state: unknown) => void;
-        useCardHeaderStyles_unstable: (state: unknown) => void;
-        useCardStyles_unstable: (state: unknown) => void;
-        useCardFooterStyles_unstable: (state: unknown) => void;
}>
}

Additional context

Have you discussed this feature with our team

No response

Validations

  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.

Priority

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant