2017-09-16 13 views
3
import "introcs"; 

export function main(): void { 
    print ("Intro"); 
    print ("a"); 
    print ("b"); 
    promptString("What would like to do?", forkMain); 
} 

export function forkMain(choice: string): void { 
    clear(); 
    if ("a") { 
     storyA(); 
    } else if ("b") { 
     storyB(); 
    } else { 
     main(); 
    } 
} 

export function storyA(): void { 
    print ("result"); 
    print ("1"); 
    print ("2"); 
    promptNumber("What would like to do?", forkA); 
} 

export function forkA(choice: number): void { 
    clear(); 
    if (1) { 
     storyC(); 
    } else if (2) { 
     storyD(); 
    } else { 
     storyA(); 
    } 
} 

export function storyB(): void { 
    print ("result"); 
    print ("3"); 
    print ("4"); 
    promptString("What would like to do?", forkB); 
} 

export function forkB(choice: number): void { 
    clear(); 
    if (1) { 
     storyE(); 
    } else if (2) { 
     storyF(); 
    } else { 
     storyB(); 
    } 
} 

export function storyC(): void { 
    print ("the end story c"); 
} 

export function storyD(): void { 
    print ("the end story d"); 
} 

export function storyE(): void { 
    print ("the end story e"); 
} 

export function storyF(): void { 
    print ("the end story f"); 
} 

main(); 

私はCYOAのための作業の初期段階にありますが、私は印刷段階に問題があります。フォークB段階になるとコードの次のエラーが表示されます。VSC @TypeScript観測可能なエラー

"severity: 'Error' 
message: 'Argument of type '(choice: number) => void' is not assignable to parameter of type '(value: string) => void'. 
    Types of parameters 'choice' and 'value' are incompatible. 
    Type 'string' is not assignable to type 'number'.'" 

私はここで間違っていますか?私はそれが私の構文を使用してだと思うが、よくわからないI'mm

 

答えて

0

promptStringの定義は次のとおりです。

function promptString(prompt: string, cb: (value: string) => void): void; 

しかし、あなたのコードの中で、あなたが入力されたforkBように、第2パラメータcbを渡していますstringと互換性がありません。(choice: number): void - number

としてご forkB変更

export function forkB(choice: string): void { 
    // ... 
} 
関連する問題