Skip to content

Playground: red squigglies on Promises in ES5 target #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Zlatkovsky opened this issue Jun 25, 2020 · 2 comments
Closed

Playground: red squigglies on Promises in ES5 target #704

Zlatkovsky opened this issue Jun 25, 2020 · 2 comments
Labels
Playground Issues that affect the Playground

Comments

@Zlatkovsky
Copy link
Member

One thing I’ve found really insightful in the past is being able to target ES5 in TS Playground, to see all of the state-machine code that gets generated.

In the recent(ish) upgrade to TS Playground, however, that scenario is moderately broken. As soon as I set the target option to ES5, I get a bunch of red squigglies, saying:

  • 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the lib compiler option to es2015 or later.
  • An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option.(2705)

image

Is there any way to still support this scenario? It seems silly to have all these red squigglies, when the code does in fact run perfectly fine in Chrome.

I could set the target to ES2015, but then I don’t get the same type of output (i.e., I see a generator function rather than the full gory details of the ES5 implementation; whereas it’s the latter that I want, screenshotted below). So what I really want is an ES5 output, but with a lib option saying that Promises should be supported.

image

@Zlatkovsky Zlatkovsky added the Playground Issues that affect the Playground label Jun 25, 2020
@orta
Copy link
Contributor

orta commented Jun 26, 2020

Hrm, so today this isn't feasible because monaco-typescript bundles lib dts files and you can either have ES5 or ES2015, not ES5 + Promise lib.

This is a symptom of #7 - which I've got some movement on and may be able to get shipped in the 4.0 beta

@orta
Copy link
Contributor

orta commented Mar 10, 2021

This is possible in modern playgrounds builds now

/// <reference lib="es2015" />

async function pause(ms:number): Promise<void> {
  return new Promise(res => setTimeout(res, ms))
}

@orta orta closed this as completed Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Playground Issues that affect the Playground
Projects
None yet
Development

No branches or pull requests

2 participants