Declare Typescript global variable as “module” type

前端 未结 3 1634
情书的邮戳
情书的邮戳 2020-12-18 06:20

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\"

3条回答
  •  隐瞒了意图╮
    2020-12-18 06:47

    The declare keyword does not declare a variable in the global scope. This keyword is used for cases in which there will be a variable in the global scope and you want to use it in a TypeScript without getting compilation errors.

    You can declare a global variable with:

    import * as R from "react";
    window.R = R;
    

提交回复
热议问题