fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

document Panel - Navigation example bug

Open x73x63 opened this issue 7 years ago • 8 comments

Environment Information

  • Package version(s): 7.5.2
  • Browser and OS versions: (fill this out if relevant)

Please provide a reproduction of the bug in a codepen:

  1. Copy Panel - Navigation code to PanelNavigationExample.tsx

  2. import use PanelNavigationExample component

  3. Failed to compile

Type '(props: IPanelProps, defaultRender: IRenderFunction) => Element' is not assignable to type 'IRenderFunction'. Types of parameters 'props' and 'props' are incompatible. Type 'IPanelProps | undefined' is not assignable to type 'IPanelProps'. Type 'undefined' is not assignable to type 'IPanelProps'. TS2322

x73x63 avatar Jun 26 '19 10:06 x73x63

Thanks for your report @x73x63. Do you mind sharing what version of TypeScript you were using when you saw the above compiler error?

I was unable to repro your issue in this sample application using TSC 3.5.1 in my IDE:

https://github.com/KevinTCoughlin/ui-fabric-ts-validation/blob/fa0648795f4292ecf4420b77903a4acf32e04736/tests/3.3/src/index.tsx#L10

If you could share a sample repro / branch that would expedite a fix if required.

KevinTCoughlin avatar Jun 26 '19 15:06 KevinTCoughlin

Thank you for your help, Has nothing to do with TypeScript vsrsion, The problem is compiler-options.

create-react-app --typescript default tsconfig.json {"strict": true,}

strict": true //Failed to compile

strict": false //OK

x73x63 avatar Jun 27 '19 01:06 x73x63

strictFunctionTypes": true //Enable strict checking of function types. Failed to compile

x73x63 avatar Jun 27 '19 02:06 x73x63

strictFunctionTypes": true //Enable strict checking of function types. Failed to compile

Thank you, that is useful information as part of the issue report :). I will discuss with the team and get back to you soonest.

KevinTCoughlin avatar Jun 27 '19 02:06 KevinTCoughlin

diff --git a/packages/office-ui-fabric-react/src/components/Panel/examples/Panel.Navigation.Example.tsx b/packages/office-ui-fabric-react/src/components/Panel/examples/Panel.Navigation.Example.tsx
index b377021d0..681883b20 100644
--- a/packages/office-ui-fabric-react/src/components/Panel/examples/Panel.Navigation.Example.tsx
+++ b/packages/office-ui-fabric-react/src/components/Panel/examples/Panel.Navigation.Example.tsx
@@ -39,7 +39,7 @@ export class PanelNavigationExample extends React.Component<
     this.setState({ showPanel: false });
   };
 
-  private _onRenderNavigationContent = (props: IPanelProps, defaultRender: IRenderFunction<IPanelProps>): JSX.Element => {
+  private _onRenderNavigationContent = (props?: IPanelProps, defaultRender?: IRenderFunction<IPanelProps>): JSX.Element => {
     const theme = getTheme();
 
     return (
@@ -106,7 +106,7 @@ export class PanelNavigationExample extends React.Component<
             iconName: 'MoreVertical'
           }}
         />
-        {defaultRender(props)}
+        {defaultRender!(props)}
       </React.Fragment>
     );
   };

The quick "fix" for this issue is more or less the above, tho we should prefer to guard rather than use a non-null assertion.

My concern with the above patch is that this is an issue with the underlying typing of IRenderFunction<P>. The incompatibility with strictFunctionTypes with respect to IRenderFunction<P> spans the codebase and should be fixed wholesale if at all.

@JasonGore @ecraig12345 do either of you have opinions here?

KevinTCoughlin avatar Jul 11 '19 23:07 KevinTCoughlin

I found other components example code also have similar problems.

Enable all strict type checking options. test all example code.

x73x63 avatar Jul 12 '19 03:07 x73x63

@x73x63 I've submitted a fix for the problem with Panel Navigation Example, I've also made an issue that's just focused on enabling strict type checking, we'll discuss it there and decide where to go next. #10226

joschect avatar Aug 21 '19 17:08 joschect

:tada:This issue was addressed in #10225, which has now been successfully released as [email protected].:tada:

Handy links:

msft-github-bot avatar Aug 22 '19 12:08 msft-github-bot