ntypescript
ntypescript copied to clipboard
Fails to use @types/react
I use ntypescript in webpack, mostly for 3rd party libraries. Recently I have added react to my project and started to get errors for @types/react:
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(171,34): error TS1005: ',' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(172,34): error TS1005: ',' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(2636,43): error TS1005: ']' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(2636,44): error TS1005: ';' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(2636,45): error TS1128: Declaration or statement expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(2636,46): error TS1128: Declaration or statement expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(2636,61): error TS1005: '(' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/react/index.d.ts
(2695,1): error TS1128: Declaration or statement expected.
The problematic source code lines (causing the first error) are:
// Base component for plain JS classes
class Component<P, S> implements ComponentLifecycle<P, S> {
constructor(props?: P, context?: any);
setState<K extends keyof S>(f: (prevState: S, props: P) => Pick<S, K>, callback?: () => any): void;
▲ The error points here
setState<K extends keyof S>(state: Pick<S, K>, callback?: () => any): void;
▲ ... and here
forceUpdate(callBack?: () => any): void;
render(): JSX.Element | null;
Is it caused by the fact that the type definition uses some syntax/features introduced in Typescript 2.2? Is there a workaround?
Just upgraded @types/lodash and got similar errors:
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(11587,21): error TS1005: ']' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(11587,22): error TS1005: ';' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(11587,23): error TS1128: Declaration or statement expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(11587,33): error TS1005: ']' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(11587,34): error TS1005: ')' expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(11587,35): error TS1128: Declaration or statement expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(11587,37): error TS1128: Declaration or statement expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(19580,1): error TS1128: Declaration or statement expected.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(241,13): error TS2300: Duplicate identifier '_'.
ERROR in /Users/korya/dev/superapp/node_modules/@types/lodash/index.d.ts
(245,19): error TS2300: Duplicate identifier '_'.
The problematic source code (causing the first error):
type ConformsPredicateObject<T> = {
[P in keyof T]: (val: T[P]) => boolean;
▲ The error points here
};