Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

typescript: declare module exports?

How can i declare that a ts file or files exports some methods?

For example there is a es6 file toyota.ts

export const turnLeft: number = (param1: string, param2: number) => {
  // do it...
}
export const turnRight: number = (param1: string, param2: number) => {
  // do it...
}

A second es6 file honda.ts

export const turnLeft: number = (param1: string, param2: number) => {
  // do it...
}
export const turnRight: number = (param1: string, param2: number) => {
  // do it...
}

How can i make a type file which describes both these ts files. i.e. declare that the file has two exports which are called turnLeft and turnRight.

So that if I have a third file nissan.ts and it only has turnLeft, then when I do tsc it will tell me the error?

I have tried to enforce the toyota.ts by making a toyota.d.ts file with declare in it. But when tsc -w runs it does not even reload when i change the toyota.d.ts. Having the toyota.d.ts did nothing. So i could not even get the first step of getting one of the js file's exports to be checked, let alone all 3 files checked using the same declaration.

Thanks for any help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...