document Panel - Navigation example bug
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:
-
Copy Panel - Navigation code to PanelNavigationExample.tsx
-
import use PanelNavigationExample component
-
Failed to compile
Type '(props: IPanelProps, defaultRender: IRenderFunction
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.
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
strictFunctionTypes": true //Enable strict checking of function types. Failed to compile
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.
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?
I found other components example code also have similar problems.
Enable all strict type checking options. test all example code.
@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
:tada:This issue was addressed in #10225, which has now been successfully released as [email protected].:tada:
Handy links: