Skip to content

Commit 6215f5c

Browse files
alex-pageBPScottaaronccasanova
authored
Remove downlevel-dts and legacy type support (#8203)
### WHY are these changes introduced? Polaris currently supports multiple TypeScript versions by building our types twice. This breaking change in v11 removes this functionality and we will only support the current version in the library. This used to be required to build the props table on legacy.polaris.shopify.com. This is no longer a requirement with @martenbjork brilliant work. ### WHAT is this pull request doing? Removes legacy type support for the library. --------- Co-authored-by: Ben Scott <227292+BPScott@users.noreply.github.com> Co-authored-by: Aaron Casanova <32409546+aaronccasanova@users.noreply.github.com>
1 parent fa47aa5 commit 6215f5c

File tree

11 files changed

+35
-66
lines changed

11 files changed

+35
-66
lines changed

documentation/guides/migrating-from-v10-to-v11.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ Polaris v11.0.0 ([full release notes](https://github.com/Shopify/polaris/release
1414

1515
NodeJS version 14 is no longer supported. NodeJS 18 is recommended and 16 is the minimum supported version.
1616

17+
## TypeScript
18+
19+
Built types in `@shopify/polaris` have moved from `build/ts/latest` to `build/ts`.
20+
21+
**Legacy TypeScript Support**
22+
23+
Polaris no longer supports multiple versions of TypeScript with downlevel-dts. Polaris only builds one set of types based on the current version of TypeScript in the project.
24+
1725
## Components
1826

1927
### Removed deprecated Collapsible argument

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"@types/jest": "^27.5.1",
7070
"@types/node": "^18.11.18",
7171
"babel-loader": "^9.1.2",
72-
"downlevel-dts": "^0.6.0",
7372
"eslint": "^8.3.0",
7473
"execa": "^5.0.0",
7574
"jest": "^27.5.1",
@@ -85,7 +84,7 @@
8584
"stylelint": "^14.15.0",
8685
"ts-node": "^10.7.0",
8786
"turbo": "^1.2.8",
88-
"typescript": "^4.6.3"
87+
"typescript": "^4.9.3"
8988
},
9089
"prettier": "@shopify/prettier-config",
9190
"size-limit": [

polaris-cli/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
"@oclif/core": "^1.13.10",
2727
"@shopify/polaris-migrator": "^0.11.3"
2828
},
29-
"devDependencies": {
30-
"typescript": "^4.7.4"
31-
},
3229
"engine-strict": true,
3330
"engines": {
3431
"node": "^16.13.0 || >=18.12.0"

polaris-react/package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,10 @@
3939
"main": "build/cjs/index.js",
4040
"module": "build/esm/index.js",
4141
"esnext": "build/esnext/index.esnext",
42-
"types": "build/ts/latest/src/index.d.ts",
43-
"typesVersions": {
44-
"<4.0": {
45-
"build/types/latest/*": [
46-
"build/ts/3.4/*"
47-
]
48-
}
49-
},
42+
"types": "build/ts/src/index.d.ts",
5043
"scripts": {
51-
"build": "run-s build:types build:types-downlevel build:js build:validate",
44+
"build": "run-s build:types build:js build:validate",
5245
"build:types": "tsc -b",
53-
"build:types-downlevel": "downlevel-dts './build/ts/latest' './build/ts/3.4'",
5446
"build:js": "rollup -c",
5547
"build:validate": "node scripts/build-validate.js",
5648
"dev": "yarn run storybook",

polaris-react/scripts/build-validate.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ function validateEsNextBuild() {
8282
}
8383

8484
function validateAncillaryOutput() {
85-
assert.ok(fs.existsSync('./build/ts/latest/src/index.d.ts'));
86-
// Downleveled for consumers on older TypeScript versions
87-
assert.ok(fs.existsSync('./build/ts/3.4/src/index.d.ts'));
85+
assert.ok(fs.existsSync('./build/ts/src/index.d.ts'));
8886
}
8987

9088
function validateVersionReplacement() {

polaris-react/src/components/OptionList/tests/OptionList.test.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,8 @@ function firstOption(
539539
options?: OptionDescriptor[],
540540
sections?: OptionListProps['sections'],
541541
): string {
542-
const firstOptionsValue =
543-
options == null || options === [] ? '' : options[0].value;
544-
const firstSectionOptionsValue =
545-
sections == null || sections === [] || sections[0].options === []
546-
? ''
547-
: sections[0].options[0].value;
542+
const firstOptionsValue = options?.[0]?.value ?? '';
543+
const firstSectionOptionsValue = sections?.[0]?.options?.[0]?.value ?? '';
548544
return firstOptionsValue || firstSectionOptionsValue;
549545
}
550546

polaris-react/src/components/ResourceList/ResourceList.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {
2-
ReactElement,
32
useCallback,
43
useEffect,
54
useReducer,
@@ -41,7 +40,11 @@ import styles from './ResourceList.scss';
4140
const SMALL_SPINNER_HEIGHT = 28;
4241
const LARGE_SPINNER_HEIGHT = 45;
4342

44-
function getAllItemsOnPage<TItemType>(
43+
interface ResourceListItemData {
44+
[data: string]: any;
45+
}
46+
47+
function getAllItemsOnPage<TItemType extends ResourceListItemData>(
4548
items: TItemType[],
4649
idForItem: (item: TItemType, index: number) => string,
4750
) {
@@ -57,16 +60,16 @@ const isBreakpointsXS = () => {
5760
parseFloat(toPx(tokens.breakpoints['breakpoints-sm']) ?? '');
5861
};
5962

60-
function defaultIdForItem<TItemType extends {id?: any}>(
63+
function defaultIdForItem<TItemType extends ResourceListItemData>(
6164
item: TItemType,
6265
index: number,
63-
) {
64-
return Object.prototype.hasOwnProperty.call(item, 'id')
65-
? item.id
66-
: index.toString();
66+
): string {
67+
return 'id' in item ? item.id : index.toString();
6768
}
6869

69-
export interface ResourceListProps<TItemType = any> {
70+
export interface ResourceListProps<
71+
TItemType extends ResourceListItemData = ResourceListItemData,
72+
> {
7073
/** Item data; each item is passed to renderItem */
7174
items: TItemType[];
7275
filterControl?: React.ReactNode;
@@ -119,13 +122,7 @@ export interface ResourceListProps<TItemType = any> {
119122
resolveItemId?(item: TItemType): string;
120123
}
121124

122-
type ResourceListType = (<TItemType>(
123-
value: ResourceListProps<TItemType>,
124-
) => ReactElement) & {
125-
Item: typeof ResourceItem;
126-
};
127-
128-
export const ResourceList: ResourceListType = function ResourceList<TItemType>({
125+
export function ResourceList<TItemType extends ResourceListItemData>({
129126
items,
130127
filterControl,
131128
emptyState,
@@ -767,6 +764,6 @@ export const ResourceList: ResourceListType = function ResourceList<TItemType>({
767764
<div ref={bulkActionsIntersectionRef} />
768765
</ResourceListContext.Provider>
769766
);
770-
};
767+
}
771768

772769
ResourceList.Item = ResourceItem;

polaris-react/src/utilities/merge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function merge<TSource1, TSource2, TSource3, TSource4, TSource5>(
3030
let final = {};
3131

3232
for (const obj of objs) {
33-
final = mergeRecursively(final, obj);
33+
final = mergeRecursively(final, obj as any);
3434
}
3535

3636
return final;

polaris-react/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"composite": true,
55
"emitDeclarationOnly": true,
66
"importsNotUsedAsValues": "error",
7-
"outDir": "build/ts/latest",
7+
"outDir": "build/ts",
88
"rootDir": "./",
99
"strictFunctionTypes": false,
1010
"paths": {

polaris.shopify.com/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@
7070
"rehype-raw": "^6.1.1",
7171
"sass": "^1.49.9",
7272
"style-loader": "^3.3.1",
73-
"typescript": "^4.7.4"
73+
"typescript": "^4.9.3"
7474
}
7575
}

0 commit comments

Comments
 (0)