I have the React type definition file (that is declared using an external module). In my source files, I usually do:
import * as R from "react"
and can then happily use R.createElement(...
etc in a strongly typed fashion.
What I want is to not have to import R
in every file, and instead have it as a global declaration (yes, I'm willing to polute the global namespace with a few variables). I've tried:
import * as React from "react";
declare var R : React;
This doesn't work though, I get "Cannot find name 'React'"
. Is there another way to export the entire module as global?
Edit 1 -
I should have made clearer: I'm interested in how to export a global type definition in a .d.ts
file. So assume I've attached R
to window
already. Now I need typescript to know that R
is of type React module
.