Skip to content

FR: Either multiline support or stop-paste-on-error #1352

@qpwo

Description

@qpwo

Desired Behavior

Copy-paste below code into ts-node twice, and only get Duplicate function implementation error.

function add(x: number, y: number): number {
    return x + y
}

Current behavior

$ ts-node
> function add(x: number, y: number): number {
...     return x + y
... }
'use strict'
> function add(x: number, y: number): number {
[eval].ts:1:10 - error TS2393: Duplicate function implementation.

1 function add(x: number, y: number): number {
           ~~~
[eval].ts:4:10 - error TS2393: Duplicate function implementation.

4 function add(x: number, y: number): number {
           ~~~
[eval].ts:4:37 - error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.

4 function add(x: number, y: number): number {
                                      ~~~~~~
[eval].ts:5:1 - error TS1005: '}' expected.

5 
  

  [eval].ts:4:44
    4 function add(x: number, y: number): number {
                                                 ~
    The parser expected to find a '}' to match the '{' token here.

undefined
>     return x + y
[eval].ts:4:5 - error TS1108: A 'return' statement can only be used within a function body.

4     return x + y
      ~~~~~~

undefined
> }
[eval].ts:4:1 - error TS1128: Declaration or statement expected.

4 }
  ~

undefined
> 

Is this request related to a problem?

Frustrated when I paste in a function I've defined before and get a pile of errors.

Alternatives you've considered

You can put the code in a block to redefine functions, but maybe I'd rather get the error.

ts-node
> function add(x: number, y: number): number {
... return x + y;
... }
'use strict'
> add(5,10)
15
> {
...     function add(x: number, y: number): number {
.....     return x + x + y + y;
.....     }
... }
[Function: add]
> 
undefined
> add(5,10)
30
> 

Additional context

I heard there is better multiline support coming to node repl sometime and it might automatically solve this. I don't know much about REPLs or if you have a reliable way to detect if code is being pasted instead of typed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    you can do thisGood candidate for a pull request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions