Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript 3.9 #50

Open
jayenashar opened this issue Jun 18, 2020 · 9 comments
Open

TypeScript 3.9 #50

jayenashar opened this issue Jun 18, 2020 · 9 comments

Comments

@jayenashar
Copy link

I tried to upgrade to get some esnext features, but there seem to be some breaking changes. I think https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#type-parameters-that-extend-any-no-longer-act-as-any . Getting errors with combineReducers.ts in various places and About.tsx with setPopoverEvent(e.nativeEvent);

9.chunk.js:113347 src/data/combineReducers.ts
TypeScript error in src/data/combineReducers.ts(3,47):
Type 'R[K]' does not satisfy the constraint '(...args: any) => any'.
  Type 'R[keyof R]' is not assignable to type '(...args: any) => any'.
    Type 'R[string] | R[number] | R[symbol]' is not assignable to type '(...args: any) => any'.
      Type 'R[string]' is not assignable to type '(...args: any) => any'.  TS2344

    1 | export function combineReducers<R extends any>(reducers: R) {
    2 |   type keys = keyof typeof reducers;
  > 3 |   type returnType = { [K in keys]: ReturnType<typeof reducers[K]> }
      |                                               ^
    4 |   const combinedReducer = (state: any, action: any) => {
    5 |     const newState: returnType = {} as any;
    6 |     const keys = Object.keys(reducers);
console.<computed> @ 9.chunk.js:113347
9.chunk.js:113347 src/data/combineReducers.ts
TypeScript error in src/data/combineReducers.ts(6,30):
No overload matches this call.
  Overload 1 of 2, '(o: {}): string[]', gave the following error.
    Argument of type 'R' is not assignable to parameter of type '{}'.
      Type 'unknown' is not assignable to type '{}'.
  Overload 2 of 2, '(o: object): string[]', gave the following error.
    Argument of type 'R' is not assignable to parameter of type 'object'.
      Type 'unknown' is not assignable to type 'object'.  TS2769

    4 |   const combinedReducer = (state: any, action: any) => {
    5 |     const newState: returnType = {} as any;
  > 6 |     const keys = Object.keys(reducers);
      |                              ^
    7 |     keys.forEach(key => {
    8 |       const result = reducers[key](state[key], action);
    9 |       newState[key as keys] = result || state[key];
console.<computed> @ 9.chunk.js:113347
9.chunk.js:113347 src/data/combineReducers.ts
TypeScript error in src/data/combineReducers.ts(8,22):
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'unknown'.
  No index signature with a parameter of type 'string' was found on type 'unknown'.  TS7053

     6 |     const keys = Object.keys(reducers);
     7 |     keys.forEach(key => {
  >  8 |       const result = reducers[key](state[key], action);
       |                      ^
     9 |       newState[key as keys] = result || state[key];
    10 |     });
    11 |     return newState;
console.<computed> @ 9.chunk.js:113347
9.chunk.js:113347 src/pages/About.tsx
TypeScript error in src/pages/About.tsx(15,21):
Argument of type 'MouseEvent' is not assignable to parameter of type 'SetStateAction<undefined>'.
  Type 'MouseEvent' provides no match for the signature '(prevState: undefined): undefined'.  TS2345

    13 | 
    14 |   const presentPopover = (e: React.MouseEvent) => {
  > 15 |     setPopoverEvent(e.nativeEvent);
       |                     ^
    16 |     setShowPopover(true);
    17 |   };
    18 |   const conferenceDate = '2047-05-17';
@shadowzack
Copy link

have you been able to fix it

@jayenashar
Copy link
Author

i upgraded to 3.7 only

@shadowzack
Copy link

I guess I will use the same version thanks

@gdijkhoffz
Copy link

So do you all not get the error if you run typescript version 3.7? I tried that and I kept getting the error, so I'm not sure how to move forward. Does anyone know what the actual fix is?

@jayenashar
Copy link
Author

i do not get the error with ts 3.7.

the actual fix is to not use typescript. i.e. rename the file to .js and remove all the types.

@SidMorad
Copy link

I just want to mention typescript 3.8.3 (with this project setup) works fine for me.

@Ishma59
Copy link

Ishma59 commented Jul 23, 2021

use ts 3.8.3 and set const [popoverEvent, setPopoverEvent] = useState<any>();

@yrcs
Copy link

yrcs commented Aug 28, 2021

It's so easy to solve "Type 'R[K]' does not satisfy the constraint '(...args: any) => any'".
Just change "combineReducers" function signature -- function combineReducers<R extends any>(reducers: R)
to function combineReducers<R extends { [key: string]: any }>(reducers: R)

@ngbsoft
Copy link

ngbsoft commented Sep 27, 2021

It's so easy to solve "Type 'R[K]' does not satisfy the constraint '(...args: any) => any'".
Just change "combineReducers" function signature -- function combineReducers<R extends any>(reducers: R)
to function combineReducers<R extends { [key: string]: any }>(reducers: R)

Simple but beautiful. Thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants