Skip to content

Commit eaa1b65

Browse files
Hotellling1726
andauthored
chore: enable full strict mode for converged packages with new DX setup (#18524)
* chore: enable full strict mode for converged packages with new DX setup * fix(react-menu): resolve tsc errors that appeared after enabling full strict mode * fix(react-storybook): make tsc pass in strict mode * Change files * docs: update packages/react-menu/src/components/Menu/Menu.test.tsx Co-authored-by: ling1726 <lingfangao@hotmail.com>
1 parent 417f308 commit eaa1b65

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "fix(react-menu): resolve tsc errors that appeared after enabling full strict mode",
4+
"packageName": "@fluentui/react-menu",
5+
"email": "martinhochel@microsoft.com",
6+
"dependentChangeType": "none"
7+
}

packages/react-menu/src/components/Menu/Menu.test.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ describe('Menu', () => {
151151
});
152152

153153
it.each([
154-
['menuitem', MenuItem],
155-
['menuitemradio', MenuItemRadio],
156-
])('should close menu after clicking on %s', (role, MenuItemComponent) => {
154+
['menuitem', MenuItem, {}],
155+
['menuitemradio', MenuItemRadio, { name: 'test', value: 'test' }],
156+
])('should close menu after clicking on %s', (role, MenuItemComponent, props) => {
157157
// Arrange
158158
const { getByRole, queryByRole } = render(
159159
<Menu>
@@ -162,7 +162,9 @@ describe('Menu', () => {
162162
</MenuTrigger>
163163
<MenuPopover>
164164
<MenuList>
165-
<MenuItemComponent>Item</MenuItemComponent>
165+
{/* eslint-disable-next-line @fluentui/max-len */}
166+
{/* @ts-expect-error - MenuItemComponent is union of 2 non-matching interfaces. Unnecessary narrowing logic would be needed which is out of scope for what is being tested */}
167+
<MenuItemComponent {...props}>Item</MenuItemComponent>
166168
</MenuList>
167169
</MenuPopover>
168170
</Menu>,
@@ -177,10 +179,10 @@ describe('Menu', () => {
177179
});
178180

179181
it.each([
180-
['menuitem', MenuItem],
181-
['menuitemcheckbox', MenuItemCheckbox],
182-
['menuitemradio', MenuItemRadio],
183-
])('should not close menu after clicking on a disabled %s', (role, MenuItemComponent) => {
182+
['menuitem', MenuItem, {}],
183+
['menuitemcheckbox', MenuItemCheckbox, { name: 'test', value: 'test' }],
184+
['menuitemradio', MenuItemRadio, { name: 'test', value: 'test' }],
185+
])('should not close menu after clicking on a disabled %s', (role, MenuItemComponent, props) => {
184186
// Arrange
185187
const { getByRole } = render(
186188
<Menu>
@@ -189,7 +191,11 @@ describe('Menu', () => {
189191
</MenuTrigger>
190192
<MenuPopover>
191193
<MenuList>
192-
<MenuItemComponent disabled>Item</MenuItemComponent>
194+
{/* eslint-disable-next-line @fluentui/max-len */}
195+
{/* @ts-expect-error - MenuItemComponent is union of 3 non-matching interfaces. Unnecessary narrowing logic would be needed which is out of scope for what is being tested */}
196+
<MenuItemComponent disabled {...props}>
197+
Item
198+
</MenuItemComponent>
193199
</MenuList>
194200
</MenuPopover>
195201
</Menu>,
@@ -203,7 +209,7 @@ describe('Menu', () => {
203209
getByRole(role);
204210
});
205211

206-
// THID ONE
212+
// THIRD ONE
207213
it.each([
208214
['menuitemcheckbox', MenuItemCheckbox],
209215
['menuitemradio', MenuItemRadio],

packages/react-menu/src/utils/useOnMenuEnter.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,25 @@ export const useOnMenuMouseEnter = (options: UseOnClickOrScrollOutsideOptions) =
3636
});
3737

3838
React.useEffect(() => {
39+
// eslint-disable-next-line eqeqeq
40+
if (element == null) {
41+
return;
42+
}
43+
44+
/**
45+
* Because `addEventListener` type override falls back to 2nd definition (evt name is unknown string literal)
46+
* evt is being typed as a base class of MouseEvent -> `Event`.
47+
* This type is used to override `listener` calls to make TS happy
48+
*/
49+
50+
type ListenerOverride = (evt: Event) => void;
51+
3952
if (!disabled) {
40-
element?.addEventListener(MENU_ENTER_EVENT, listener);
53+
element.addEventListener(MENU_ENTER_EVENT, listener as ListenerOverride);
4154
}
4255

4356
return () => {
44-
element?.removeEventListener(MENU_ENTER_EVENT, listener);
57+
element.removeEventListener(MENU_ENTER_EVENT, listener as ListenerOverride);
4558
};
4659
}, [listener, element, disabled]);
4760
};

packages/react-storybook/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
"declaration": true,
1010
"importHelpers": true,
1111
"noUnusedLocals": true,
12-
"strict": true,
1312
"preserveConstEnums": true,
14-
"types": ["jest", "custom-global"]
13+
"types": ["jest", "custom-global", "inline-style-expand-shorthand"]
1514
},
1615
"include": ["src"]
1716
}

tsconfig.base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"lib": ["ES2015", "dom"],
77
"sourceMap": true,
88
"strict": true,
9-
"strictFunctionTypes": false,
109
"forceConsistentCasingInFileNames": true,
1110
"skipLibCheck": true,
1211
"typeRoots": ["node_modules/@types", "./typings"],

0 commit comments

Comments
 (0)