Skip to content

RFC: Improving bug reports by supporting inline reproductions #35389

Closed
@orta

Description

@orta

We want to provide better tools for providing reproductions of TypeScript bugs in issues. In an issue we really only have text to work with, so we need some kind of text representation of a TypeScript project.

Classes of issues

Looking through the bugs label, there are a large amounts of cases we can probably address:

  • Bad JS/DTS Emit
  • This code should be this type
  • This code is slow to compile / use IntelliSense
  • This code crashes
  • This code should error
  • This code should not error
  • This refactor didn't do what I expected

There are a few we probably can't:

  • This code infinite loops

I'm interested in expanding either of these lists! ^

Possible solution

Two parts:

  • We use something like arcanis/sherlock to run any issues with re-pros on a nightly-ish schedule with different builds of TypeScript and store the results using something like this - this runs TypeScript code with markup which is built for repros

  • A page on the website which helps you generate a single typescript codeblock which is a reproduction of a bug

Possible Markup

We've been working on a TypeScript markup language for the website and this called ts-twoslash which adds commands inside comments. I'd recommend reading the README for that before expanding some of these examples.

Bad JS Emit
// @showEmit
// @emitShouldContain: this string
// @emitShouldNotContain: this other string

console.log("hello world")
Bad DTS Emit
// @showEmit
// @showEmittedFile: index.d.ts
// @emitShouldContain: 123
// @emitShouldNotContain: 456

export const myVariable = "123123"
This code should be this type
// @noImplicitAny: false

const a = 123
//    ^? = const a: 123

or

// @noImplicitAny: false

const a = 123
//    ^? != const a: any
This code is slow
// @slow

const a = 123
//    ^?

This annotation could indicate that it should fail if it takes over 1s

This code crashes
const a = 123
a.l

In theory there shouldn't need to be a crashes annotation, all code should not crash. I'm open to debates on why that might need to be different though.

This code should error
// @expectErrors: 4311

const a = "hello"
a * a
This code should not error
const a = "hello"
a * a

The lack of an error annotation should indicate this. If it is expected that there should be some errors, then it can use the @errors: 3211 which is already set up

This refactor didn't do what I expected

I'm still a bit hazy on this, in fourslash there are a lot of options here - but to try provide a really high-level

const a = "hello"
   a * a
// ^^^^^! refactor

This could create a JSON dump of all the refactoring options maybe?

Web Page

We have been working towards having the playground support a custom set of tabs in the sidebar, it's not a far reach to imagine that an editor for twoslash could be the playground but with tabs focused on running ts-twoslash and getting useful results.

Here's a rough idea of what that could feel like:

Screen Shot 2019-11-27 at 12 03 02 PM

The blockers on that:

Metadata

Metadata

Assignees

No one assigned

    Labels

    InfrastructureIssue relates to TypeScript team infrastructure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions