在JavaScript中导入/需要文件(而不是模块)时,如何使用类型定义?
我有三个文件: a.js在JavaScript中导入/需要文件(而不是模块)时,如何使用类型定义?,javascript,reactjs,typescript,create-react-app,Javascript,Reactjs,Typescript,Create React App,我有三个文件: a.js var moduleb=require('./b.js') moduleb.func('should_be_a_string_and_return_a_boolen') function func(arg){ return arg } module.exports={func} declare function fnc(arg:string):boolean b.js var moduleb=require('./b.js') modul
var moduleb=require('./b.js')
moduleb.func('should_be_a_string_and_return_a_boolen')
function func(arg){
return arg
}
module.exports={func}
declare function fnc(arg:string):boolean
b.js
var moduleb=require('./b.js')
moduleb.func('should_be_a_string_and_return_a_boolen')
function func(arg){
return arg
}
module.exports={func}
declare function fnc(arg:string):boolean
b.d.ts
var moduleb=require('./b.js')
moduleb.func('should_be_a_string_and_return_a_boolen')
function func(arg){
return arg
}
module.exports={func}
declare function fnc(arg:string):boolean
问题是: 如何使TypeScript编译器理解
b.d.ts
中的类型定义,并将其连接到b.js
中的导出值
我想要达到的目标是什么?
我正在使用create react app
,我想为组件添加类型定义,这样我就可以为组件的所有道具提供IntelliSense
谢谢 具有各自.d.ts类型的模块(CommonJS和ES)可以像往常一样在TypeScript中导入:
import * as moduleb from './b.js';
或:
而require
withoutimport
语句应该用于没有打字和同步动态导入的模块