diff --git a/.github/workflows/build-and-test-types.yml b/.github/workflows/build-and-test-types.yml index e99ca03a7..016b859e8 100644 --- a/.github/workflows/build-and-test-types.yml +++ b/.github/workflows/build-and-test-types.yml @@ -8,7 +8,7 @@ on: jobs: build: - name: Lint, Test, Report Coverage on Node ${{ matrix.node }} + name: Build and Test on Node ${{ matrix.node }} runs-on: ubuntu-latest strategy: matrix: @@ -57,13 +57,14 @@ jobs: fail-fast: false matrix: node: ['16.x'] - ts: ['4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9', '5.0'] + ts: ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2'] + steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Use node ${{ matrix.node }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} cache: 'yarn' @@ -94,6 +95,28 @@ jobs: ./node_modules/.bin/tsc --version yarn test:typescript + are-the-types-wrong: + name: Check package config with are-the-types-wrong + + needs: [build] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node: ['16.x'] + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - uses: actions/download-artifact@v3 + with: + name: package + path: . + + # Note: We currently expect "FalseCJS" failures for Node16 + `moduleResolution: "node16", + - name: Run are-the-types-wrong + run: npx @arethetypeswrong/cli ./package.tgz --format table --ignore-rules false-cjs + test-published-artifact: name: Test Published Artifact ${{ matrix.example }} @@ -103,22 +126,13 @@ jobs: fail-fast: false matrix: node: ['16.x'] - example: - [ - 'cra4', - 'cra5', - 'next', - 'vite', - 'node-standard', - 'node-esm', - 'are-the-types-wrong' - ] + example: ['cra4', 'cra5', 'next', 'vite', 'node-standard', 'node-esm'] steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Use node ${{ matrix.node }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v3.8.1 with: node-version: ${{ matrix.node }} cache: 'yarn' @@ -126,12 +140,31 @@ jobs: - name: Clone RTK repo run: git clone https://github.com/reduxjs/redux-toolkit.git ./redux-toolkit + - name: Check out v2.0-integration + working-directory: ./redux-toolkit + run: git checkout v2.0-integration + - name: Check folder contents run: ls -l . + # Some weird install diffs with cloning this repo and installing. + # Just kill the lockfiles for this repo and RTK and reinstall + + - name: Remove top lockfile + run: rm yarn.lock && rm package.json + + - name: Remove RTK lockfile + working-directory: ./redux-toolkit + run: rm yarn.lock && rm package.json + - name: Install deps working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }} - run: yarn install + run: rm yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install + + - name: Install Playwright browser if necessary + working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }} + continue-on-error: true + run: yarn playwright install - uses: actions/download-artifact@v2 with: @@ -150,6 +183,10 @@ jobs: working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }} run: yarn info reselect && yarn why reselect + - name: Check MSW version + working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }} + run: yarn why msw + - name: Build example working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }} run: yarn build @@ -157,10 +194,3 @@ jobs: - name: Run test step working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }} run: yarn test - if: matrix.example != 'are-the-types-wrong' - - - name: Run test step (attw) - working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }} - # Ignore "FalseCJS" errors in the `attw` job - run: yarn test -n FalseCJS - if: matrix.example == 'are-the-types-wrong' diff --git a/package.json b/package.json index ff9f19c67..d43728011 100644 --- a/package.json +++ b/package.json @@ -13,13 +13,6 @@ "default": "./dist/cjs/reselect.cjs" } }, - "typesVersions": { - "<=4.6": { - "*": [ - "./dist/versionedTypes/ts46/index.d.ts" - ] - } - }, "files": [ "src", "dist" diff --git a/src/versionedTypes/package.dist.json b/src/versionedTypes/package.dist.json deleted file mode 100644 index 600d9d1e5..000000000 --- a/src/versionedTypes/package.dist.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "typesVersions": { - ">=4.7": { - "index": [ - "./ts47-mergeParameters.d.ts" - ] - }, - "<4.7": { - "index": [ - "./ts46-mergeParameters.d.ts" - ] - } - } -} diff --git a/src/versionedTypes/ts46-mergeParameters.ts b/src/versionedTypes/ts46-mergeParameters.ts deleted file mode 100644 index bf92fbff4..000000000 --- a/src/versionedTypes/ts46-mergeParameters.ts +++ /dev/null @@ -1,171 +0,0 @@ -import type { - UnknownFunction, - Expand, - TuplifyUnion, - Has, - List, - IsTuple -} from '../types' - -/** Given a set of input selectors, extracts the intersected parameters to determine - * what values can actually be passed to all of the input selectors at once - * WARNING: "you are not expected to understand this" :) - */ -export type MergeParameters< - // The actual array of input selectors - T extends readonly UnknownFunction[], - // Given those selectors, we do several transformations on the types in sequence: - // 1) Extract "the type of parameters" for each input selector, so that we now have - // a tuple of all those parameters - ParamsArrays extends readonly any[][] = ExtractParams, - // 2) Transpose the parameter tuples. - // Originally, we have nested arrays with "all params from input", "from input 2", etc: - // `[ [i1a, i1b, i1c], [i2a, i2b, i2c], [i3a, i3b, i3c] ], - // In order to intersect the params at each index, we need to transpose them so that - // we have "all the first args", "all the second args", and so on: - // `[ [i1a, i2a, i3a], [i1b, i2b, i3b], [i1c, i2c, i3c] ] - // Unfortunately, this step also turns the arrays into a union, and weirder, it is - // a union of all possible combinations for all input functions, so there's duplicates. - TransposedArrays = Transpose, - // 3) Turn the union of arrays back into a nested tuple. Order does not matter here. - TuplifiedArrays extends any[] = TuplifyUnion, - // 4) Find the longest params array out of the ones we have. - // Note that this is actually the _nested_ data we wanted out of the transpose step, - // so it has all the right pieces we need. - LongestParamsArray extends readonly any[] = LongestArray -> = - // After all that preparation work, we can actually do parameter extraction. - // These steps work somewhat inside out (jump ahead to the middle): - // 11) Finally, after all that, run a shallow expansion on the values to make the user-visible - // field details more readable when viewing the selector's type in a hover box. - ExpandItems< - // 10) Tuples can have field names attached, and it seems to work better to remove those - RemoveNames<{ - // 5) We know the longest params array has N args. Loop over the indices of that array. - // 6) For each index, do a check to ensure that we're _only_ checking numeric indices, - // not any field names for array functions like `slice()` - [index in keyof LongestParamsArray]: LongestParamsArray[index] extends LongestParamsArray[number] - ? // 9) Any object types that were intersected may have had - IgnoreInvalidIntersections< - // 8) Then, intersect all of the parameters for this arg together. - IntersectAll< - // 7) Since this is a _nested_ array, extract the right sub-array for this index - LongestParamsArray[index] - > - > - : never - }> - > - -/* - * - * Reselect Internal Utility Types - * - */ - -/* - * - * Reselect Internal Utility Types - * - */ - -/** An object with no fields */ -type EmptyObject = { - [K in any]: never -} - -type IgnoreInvalidIntersections = T extends EmptyObject ? never : T - -/** Extract the parameters from all functions as a tuple */ -export type ExtractParams = { - [index in keyof T]: T[index] extends T[number] ? Parameters : never -} - -/** Recursively expand all fields in an object for easier reading */ -export type ExpandItems = { - [index in keyof T]: T[index] extends T[number] ? Expand : never -} - -/** Select the longer of two arrays */ -export type Longest = L extends unknown - ? L1 extends unknown - ? { 0: L1; 1: L }[Has] - : never - : never - -/** Recurse over a nested array to locate the longest one. - * Acts like a type-level `reduce()` - */ -export type LongestArray = - // If this isn't a tuple, all indices are the same, we can't tell a difference - IsTuple extends '0' - ? // so just return the type of the first item - S[0] - : // If there's two nested arrays remaining, compare them - S extends [any[], any[]] - ? Longest - : // If there's more than two, extract their types, treat the remainder as a smaller array - S extends [any[], any[], ...infer Rest] - ? // then compare those two, recurse through the smaller array, and compare vs its result - Longest< - Longest, - Rest extends any[][] ? LongestArray : [] - > - : // If there's one item left, return it - S extends [any[]] - ? S[0] - : never - -/** Recursive type for intersecting together all items in a tuple, to determine - * the final parameter type at a given argument index in the generated selector. */ -export type IntersectAll = IsTuple extends '0' - ? T[0] - : _IntersectAll - -type IfJustNullish = [T] extends [undefined | null] - ? True - : False - -/** Intersect a pair of types together, for use in parameter type calculation. - * This is made much more complex because we need to correctly handle cases - * where a function has fewer parameters and the type is `undefined`, as well as - * optional params or params that have `null` or `undefined` as part of a union. - * - * If the next type by itself is `null` or `undefined`, we exclude it and return - * the other type. Otherwise, intersect them together. - */ -type _IntersectAll = T extends [infer First, ...infer Rest] - ? _IntersectAll> - : R - -/* - * - * External/Copied Utility Types - * - */ - -/** - * Removes field names from a tuple - * Source: https://stackoverflow.com/a/63571175/62937 - */ -type RemoveNames = [any, ...T] extends [ - any, - ...infer U -] - ? U - : never - -/** - * Transposes nested arrays - * Source: https://stackoverflow.com/a/66303933/62937 - */ -type Transpose = T[Extract< - keyof T, - T extends readonly any[] ? number : unknown ->] extends infer V - ? { - [K in keyof V]: { - [L in keyof T]: K extends keyof T[L] ? T[L][K] : undefined - } - } - : never diff --git a/tsconfig.json b/tsconfig.json index 3a25ad468..daa27554a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,6 @@ "paths": { "reselect": ["src/index.ts"], // @remap-prod-remove-line "@internal/*": ["src/*"], - "./ts47-mergeParameters": ["./src/versionedTypes/ts46-mergeParameters.ts"] } }, "include": ["./src/**/*"], diff --git a/tsconfig.ts46types.json b/tsconfig.ts46types.json deleted file mode 100644 index 357d1a0cd..000000000 --- a/tsconfig.ts46types.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "./dist/versionedTypes/ts46" - }, -} diff --git a/tsup.config.ts b/tsup.config.ts index 41ac506c2..c85519b0e 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -29,18 +29,7 @@ export default defineConfig(options => { format: ['esm'], outExtension: () => ({ js: '.mjs' }), dts: true, - clean: true, - async onSuccess() { - console.log('onSuccess') - - console.log('Generating TS 4.6 types...') - await execAsync('yarn tsc -p tsconfig.ts46types.json') - fs.copyFileSync( - 'src/versionedTypes/package.dist.json', - 'dist/versionedTypes/ts46/versionedTypes/package.json' - ) - console.log('TS 4.6 types done') - } + clean: true }, // Support Webpack 4 by pointing `"module"` to a file with a `.js` extension