Skip to content

ts-node REPL: error on multiline function arguments #1667

Closed

Description

@d9k

Functions with arguments declared in one line work in ts-node REPL:

> ts-node 
> function myFn(a: string, b: string) {
...   console.log(a, b)
...   return a
... }
undefined
> myFn('test', '!')
test !
'test'

Trying to paste function with multline arguments declaration into ts-node REPL:

function myFn2(
  a: string,
  b: string
) {
  console.log(a, b)
  return a
}

result:

> ts-node
> function myFn2(
<repl>.ts:9:10 - error TS2391: Function implementation is missing or not immediately following the declaration.
             
9 function myFn2(
           ~~~~~
<repl>.ts:9:10 - error TS7010: 'myFn2', which lacks return-type annotation, implicitly has an 'any' return type.

9 function myFn2(
           ~~~~~
<repl>.ts:10:1 - error TS1005: ')' expected.

Specifications

> ts-node -vv       
ts-node v10.6.0
node v14.16.1
compiler v4.2.3
  • Operating system and version:
> cat /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=19
DISTRIB_CODENAME=tara
DISTRIB_DESCRIPTION="Linux Mint 19 Tara"
> cat /etc/upstream-release/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"

Activity

  1. changed the title [-]Multiline function arguments[/-] [+]ts-node: error on multiline function arguments[/+] on Mar 2, 2022
  2. changed the title [-]ts-node: error on multiline function arguments[/-] [+]ts-node REPL: error on multiline function arguments[/+] on Mar 2, 2022
  3. cspotcode commented on Mar 2, 2022

    @cspotcode
    Collaborator

    I'm guessing you are hitting a limitation in our known set of RECOVERY_CODES:

    ts-node/src/repl.ts

    Lines 671 to 683 in 30f03e1

    /**
    * TS diagnostic codes which are recoverable, meaning that the user likely entered and incomplete line of code
    * and should be prompted for the next. For example, starting a multi-line for() loop and not finishing it.
    */
    const RECOVERY_CODES: Set<number> = new Set([
    1003, // "Identifier expected."
    1005, // "')' expected."
    1109, // "Expression expected."
    1126, // "Unexpected end of text."
    1160, // "Unterminated template literal."
    1161, // "Unterminated regular expression literal."
    2355, // "A function whose declared type is neither 'void' nor 'any' must return a value."
    ]);

  4. added 3 commits that reference this issue on Mar 4, 2022
    16857d0
    ea6d318
    da07227
  5. d9k commented on Mar 4, 2022

    @d9k
    ContributorAuthor

    @cspotcode, created #1677 pull request

  6. modified the milestones: 10.7.0, 10.8.0 on Mar 5, 2022
  7. added a commit that references this issue on Mar 20, 2022
    98f30e8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    you can do thisGood candidate for a pull request.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions