Skip to content

Commit 581620e

Browse files
committed
fix: ts 4.1 compat
1 parent 40254e3 commit 581620e

File tree

9 files changed

+8366
-4319
lines changed

9 files changed

+8366
-4319
lines changed

.config/tsconfig.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
"include": ["../packages/**/src/**/*.ts"],
33
"exclude": ["../**/*.test.ts"],
44
"compilerOptions": {
5-
"target": "es2021",
6-
"lib": ["dom", "es2019"],
7-
"moduleResolution": "node",
8-
"module": "es2015",
9-
"removeComments": false,
5+
"lib": ["dom", "es2020"],
6+
"target": "es2020",
107
"skipLibCheck": true,
11-
"declaration": true,
12-
"emitDeclarationOnly": true,
8+
"moduleResolution": "node",
9+
"noEmit": true,
10+
"resolveJsonModule": true,
11+
"strict": true,
12+
"noUnusedLocals": true,
13+
"types": ["node", "jest", "resize-observer-browser"],
14+
"allowJs": true,
15+
"esModuleInterop": true,
1316
"jsx": "react-jsx",
1417
"outDir": "../packages",
1518
"allowSyntheticDefaultImports": true

package-lock.json

+8,336-4,301
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@playwright/test": "1.17.2",
4444
"@types/jest": "^27.0.3",
4545
"@types/node": "^16.11.10",
46+
"@types/resize-observer-browser": "^0.1.7",
4647
"@typescript-eslint/eslint-plugin": "^5.4.0",
4748
"@typescript-eslint/parser": "^5.4.0",
4849
"eslint": "^8.3.0",

packages/core/src/enums.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import type {Side, Placement} from './types';
1+
import type {Side, Placement, AlignedPlacement} from './types';
22

33
export const sides: Side[] = ['top', 'right', 'bottom', 'left'];
44
export const allPlacements = sides.reduce(
5-
(acc: Placement[], side) => acc.concat(side, `${side}-start`, `${side}-end`),
5+
(acc: Placement[], side) =>
6+
acc.concat(
7+
side,
8+
`${side}-start` as AlignedPlacement,
9+
`${side}-end` as AlignedPlacement
10+
),
611
[]
712
);

packages/core/src/middleware/offset.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export function convertValueToCoords(
4747

4848
const rawValue =
4949
typeof value === 'function' ? value({...rects, placement}) : value;
50-
const isNumber = typeof rawValue === 'number';
5150

5251
// eslint-disable-next-line prefer-const
53-
let {mainAxis, crossAxis, alignmentAxis} = isNumber
54-
? {mainAxis: rawValue, crossAxis: 0, alignmentAxis: null}
55-
: {mainAxis: 0, crossAxis: 0, alignmentAxis: null, ...rawValue};
52+
let {mainAxis, crossAxis, alignmentAxis} =
53+
typeof rawValue === 'number'
54+
? {mainAxis: rawValue, crossAxis: 0, alignmentAxis: null}
55+
: {mainAxis: 0, crossAxis: 0, alignmentAxis: null, ...rawValue};
5656

5757
if (alignment && typeof alignmentAxis === 'number') {
5858
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;

packages/dom/src/utils/getRectRelativeToOffsetParent.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function getRectRelativeToOffsetParent(
2424
const documentElement = getDocumentElement(offsetParent);
2525
const rect = getBoundingClientRect(
2626
element,
27+
// @ts-ignore - checked above (TS 4.1 compat)
2728
isOffsetParentAnElement && isScaled(offsetParent),
2829
strategy === 'fixed'
2930
);

packages/dom/src/utils/is.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function isContainingBlock(element: Element): boolean {
4949
return (
5050
css.transform !== 'none' ||
5151
css.perspective !== 'none' ||
52+
// @ts-ignore (TS 4.1 compat)
5253
css.contain === 'paint' ||
5354
['transform', 'perspective'].includes(css.willChange) ||
5455
(isFirefox && css.willChange === 'filter') ||

packages/react-dom-interactions/src/useInteractions.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function mergeProps(
2828
};
2929

3030
propsList.forEach((props) => {
31-
const elementProps = props?.[elementKey] ?? {};
31+
const elementProps = ((props && props[elementKey]) ??
32+
{}) as React.HTMLProps<Element>;
3233

3334
(
3435
Object.keys(elementProps) as Array<keyof React.HTMLProps<Element>>
@@ -47,7 +48,7 @@ function mergeProps(
4748
...(elementKey === 'floating' && {tabIndex: -1}),
4849
...userProps,
4950
...propsList.reduce((acc, props) => {
50-
Object.assign(acc, props?.[elementKey]);
51+
props && Object.assign(acc, props[elementKey]);
5152
return acc;
5253
}, {}),
5354
...Object.entries(mergePropsMap[elementKey]).reduce(

tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"compilerOptions": {
3-
"lib": ["dom", "es2021"],
4-
"target": "es2021",
3+
"lib": ["dom", "es2020"],
4+
"target": "es2020",
55
"skipLibCheck": true,
66
"moduleResolution": "node",
77
"noEmit": true,
88
"resolveJsonModule": true,
99
"strict": true,
1010
"noUnusedLocals": true,
11-
"types": ["node", "jest"],
11+
"types": ["node", "jest", "resize-observer-browser"],
1212
"allowJs": true,
1313
"esModuleInterop": true,
1414
"jsx": "react-jsx"

0 commit comments

Comments
 (0)