Skip to content

Problem with the type of promise #387

@pouyakary

Description

@pouyakary

TS and JS Grammar Extension version: VSCode 1.9 Insiders, latest daily build

Problem
problem-with-promise-types

Code

//
// Copyright 2016 Kary Foundation, Inc.
//   Author: Pouya Kary <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

//
// ─── IMPORTS ────────────────────────────────────────────────────────────────────
//

    import * as readline from 'readline';

//
// ─── READLINE ───────────────────────────────────────────────────────────────────
//

    /**
     * Reads a string from the command line
     * ```
     * async function main ( ) {
     *    let name = await kary.terminal.input('Your name: ')
     *    console.log(`Hello, ${ name }!`)
     * }
     * ```
     */
    export async function input ( message = '' ) {
        const readlineInterface = readline.createInterface({
            input: process.stdin,
            output: process.stdout,
        })
        return new Promise<string> ( resolve => {
            readlineInterface.question ( message , answer => {
                readlineInterface.close( );
                resolve( answer );
            });
        });
    }

// ────────────────────────────────────────────────────────────────────────────────

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions