Skip to content

Commit

Permalink
drop pre-TS-4.1 types and workarounds (#2249)
Browse files Browse the repository at this point in the history
* drop pre-4.1 type compatibility hack

* update test matrix, remove pre41 annotations
  • Loading branch information
phryneas committed Apr 18, 2022
1 parent a00b8b8 commit c5d5335
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 53 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
fail-fast: false
matrix:
node: ['14.x']
ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6.1-rc', 'next']
ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7.0-beta', 'next']
steps:
- name: Checkout repo
uses: actions/checkout@v2
Expand All @@ -123,10 +123,6 @@ jobs:

- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*

- name: "@ts-ignore stuff that didn't exist pre-4.1 in the tests"
if: ${{ matrix.ts < 4.1 }}
run: sed -i -e 's/@pre41-ts-ignore/@ts-ignore/' -e '/pre41-remove-start/,/pre41-remove-end/d' ./src/tests/*.* ./src/query/tests/*.ts*

- name: Test types
run: |
yarn tsc --version
Expand Down
7 changes: 0 additions & 7 deletions packages/toolkit/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,6 @@ async function main({ skipExtraction = false, local = false }: BuildArgs) {
await buildUMD(outputPath, entryPoint.prefix, entryPoint.globalName)
}

// We need one additional package.json file in dist to support
// versioned types for TS <4.1
fs.copyFileSync(
'src/query/react/versionedTypes/package.dist.json',
'dist/query/react/versionedTypes/package.json'
)

if (!skipExtraction) {
for (let entryPoint of entryPoints) {
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/react/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { capitalize } from '../utils'
import { safeAssign } from '../tsHelpers'
import type { BaseQueryFn } from '@reduxjs/toolkit/dist/query/baseQueryTypes'

import type { HooksWithUniqueNames } from './versionedTypes'
import type { HooksWithUniqueNames } from './namedHooks'

import {
useDispatch as rrUseDispatch,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { UseMutation, UseLazyQuery, UseQuery } from '../buildHooks'
import type { UseMutation, UseLazyQuery, UseQuery } from './buildHooks'
import type {
DefinitionType,
EndpointDefinitions,
MutationDefinition,
QueryDefinition,
} from '@reduxjs/toolkit/dist/query/endpointDefinitions'

// For TS 4.1 and later, we can use string literal types to define
// the exact names of each endpoint's exported hooks
export type HooksWithUniqueNames<Definitions extends EndpointDefinitions> =
keyof Definitions extends infer Keys
? Keys extends string
Expand Down
8 changes: 0 additions & 8 deletions packages/toolkit/src/query/react/versionedTypes/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/toolkit/src/query/react/versionedTypes/package.dist.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/toolkit/src/query/react/versionedTypes/ts40Types.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/toolkit/src/query/tests/buildHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1828,14 +1828,10 @@ describe('hooks with createApi defaults set', () => {

const storeRef = setupApiStore(api)

// @pre41-ts-ignore
expectExactType(api.useGetPostsQuery)(api.endpoints.getPosts.useQuery)
// @pre41-ts-ignore
expectExactType(api.useUpdatePostMutation)(
// @pre41-ts-ignore
api.endpoints.updatePost.useMutation
)
// @pre41-ts-ignore
expectExactType(api.useAddPostMutation)(api.endpoints.addPost.useMutation)

test('useQueryState serves a deeply memoized value and does not rerender unnecessarily', async () => {
Expand Down
6 changes: 0 additions & 6 deletions packages/toolkit/src/query/tests/unionTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ describe.skip('TS only tests', () => {
expectType<never>(result)
}
})
// pre41-remove-start
test('useQuery TS4.1 union', () => {
const result = api.useTestQuery()

Expand Down Expand Up @@ -207,7 +206,6 @@ describe.skip('TS only tests', () => {
expectType<never>(result)
}
})
// pre41-remove-end

test('useLazyQuery union', () => {
const [_trigger, result] = api.endpoints.test.useLazyQuery()
Expand Down Expand Up @@ -275,7 +273,6 @@ describe.skip('TS only tests', () => {
}
})

// pre41-remove-start
test('useLazyQuery TS4.1 union', () => {
const [_trigger, result] = api.useLazyTestQuery()

Expand Down Expand Up @@ -341,7 +338,6 @@ describe.skip('TS only tests', () => {
expectType<never>(result)
}
})
// pre41-remove-end

test('queryHookResult (without selector) union', () => {
const useQueryStateResult = api.endpoints.test.useQueryState()
Expand Down Expand Up @@ -501,7 +497,6 @@ describe.skip('TS only tests', () => {
})(result)
})

// pre41-remove-start
test('useMutation TS4.1 union', () => {
const [_trigger, result] = api.useMutationMutation()

Expand Down Expand Up @@ -552,5 +547,4 @@ describe.skip('TS only tests', () => {
expectType<never>(result)
}
})
// pre41-remove-end
})

0 comments on commit c5d5335

Please sign in to comment.