Typescript: Cannot compile jsx if we provide `noImplicitAny` option

Created on 30 Jun 2015  路  4Comments  路  Source: microsoft/TypeScript

we cannot compile jsx if we provide noImplicitAny option.

Reproducible revision

https://github.com/Microsoft/TypeScript/commit/fe4612273ccc2017cfec598521eec5ce30bbd4dc

Testcase

command

tsc test.tsx --jsx react --noImplicitAny

test case: test.tsx

<div>test</div>

Actual Result

test.tsx(1,1): error TS2602: JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist.
test.tsx(1,1): error TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists

Expected Result

Success the compilation if we provide noImplicitAny option.

Remarks

Of course, this will be success if we don't provide noImplicitAny option.

Question

Most helpful comment

Got bitten by this, but now react-jsx.d.ts doesn't exists on DefinitelyTyped. Currently the options seems to be:

typings install react

typings install dt~react --global

npm install @types/react

All 4 comments

As the errors say:

because the global type 'JSX.Element' does not exist.

and

because no interface 'JSX.IntrinsicElements' exists

If you want to compile JSX files without implicit any errors, you can define those types:

declare namespace JSX {
  interface Element { }
  interface IntrinsicElements { div: any; }
}

I recommend getting the react-jsx.d.ts file from DefinitelyTyped

aha. Thank you!

Got bitten by this, but now react-jsx.d.ts doesn't exists on DefinitelyTyped. Currently the options seems to be:

typings install react

typings install dt~react --global

npm install @types/react

@nahuel not REMOVED, just not yet 'ported'. Glad to iterate on it if you wouldn't mind opening an issue for it. Or feel free to make a PR. Won't take much to make it external module friendly.

I'll get right to it when I get back this weekend from traveling.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

uber5001 picture uber5001  路  3Comments

blendsdk picture blendsdk  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments