我要創造我自己的分型DefinitelyTyped的排名項目(https://github.com/maxcnunes/ranking)我應該怎麼做來創建自己的分型DefinitelyTyped具有默認爲
我已經嘗試以下一些實施...
declare module 'ranking' {
interface RankingPlayer {
position: number
score: number
playerId: any
}
interface Ranking {
maxScore: number
branchFactor: number
players: any
find(query);
findOne(query);
setScore(player: RankingPlayer);
addPlayerPoints(player: RankingPlayer);
}
interface RankingStatic {
(config: any): Ranking;
}
var ranking: RankingStatic;
export = ranking;
}
當我試着使用代碼
import Ranking from 'ranking'
...
console.log(Ranking) // This out '[Function: Ranking]'
const ranking = new Ranking({}) // This Error 'Cannot call a class as a function'
所以我用以下代碼再試一次......
declare module 'ranking' {
interface RankingPlayer {
position: number
score: number
playerId: any
}
export default class Ranking {
maxScore: number
branchFactor: number
players: any
constructor(config: any)
find(query)
findOne(query)
setScore(player: RankingPlayer)
addPlayerPoints(player: RankingPlayer)
}
}
,及代碼
import Ranking from 'ranking'
...
console.log(Ranking) // This out 'undefined'
const ranking = new Ranking({}) // This Error 'ranking_1.default is not a constructor'
不知道什麼應該做,以實現這個:(
我認爲這不是你的打字問題,而不是你的構建過程。你能補充一點嗎? –
@SebastianSebald我不知道什麼是構建過程? –
由於您必須將您的TypeScript代碼轉換爲JavaScript,我想您有某種過程可以實現這一點。或者是IDE中顯示的錯誤? –