Promise' only refers to a type, but is being used as a value here The Next CEO of Stack OverflowAre strongly-typed functions as parameters possible in TypeScript?Typescript: Interfaces vs Typestypescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here''Promise' only refers to a type, but is being used as a value here'Set' only refers to a type, but is being used as a value here. (TS2693)React Fragment results in Element Type is Invalid Error in Visual Studio 2017Typescript cannot find module in node_modules that I created myself locallywebpack unable to load typescript definitionsTS2585: 'Promise' only refers to a type, but is being used as a value hereTypeScript type guards and “only refers to a type, but is being used as a value here.”

How to Implement Deterministic Encryption Safely in .NET

Is it correct to say moon starry nights?

Yu-Gi-Oh cards in Python 3

Airplane gently rocking its wings during whole flight

The Ultimate Number Sequence Puzzle

"Eavesdropping" vs "Listen in on"

What happened in Rome, when the western empire "fell"?

Inductor and Capacitor in Parallel

What steps are necessary to read a Modern SSD in Medieval Europe?

Calculate the Mean mean of two numbers

It is correct to match light sources with the same color temperature?

How to get the last not-null value in an ordered column of a huge table?

Do scriptures give a method to recognize a truly self-realized person/jivanmukta?

TikZ: How to fill area with a special pattern?

Why did early computer designers eschew integers?

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Defamation due to breach of confidentiality

Help! I cannot understand this game’s notations!

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Physiological effects of huge anime eyes

Purpose of level-shifter with same in and out voltages

Asymptote: 3d graph over a disc

What difference does it make using sed with/without whitespaces?



Promise' only refers to a type, but is being used as a value here



The Next CEO of Stack OverflowAre strongly-typed functions as parameters possible in TypeScript?Typescript: Interfaces vs Typestypescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here''Promise' only refers to a type, but is being used as a value here'Set' only refers to a type, but is being used as a value here. (TS2693)React Fragment results in Element Type is Invalid Error in Visual Studio 2017Typescript cannot find module in node_modules that I created myself locallywebpack unable to load typescript definitionsTS2585: 'Promise' only refers to a type, but is being used as a value hereTypeScript type guards and “only refers to a type, but is being used as a value here.”










0















Sort of trying to figure out how asynchronous stuff works in typescript and when I run my compiler it yields this error. Here is the code I'm trying to compile:



Printer.ts



export class Printer

public static printString(string: string, callback): void

setTimeout(
() =>
console.log(string)
callback()
,
Math.floor(Math.random() * 100) + 1
)


public static printStringWithPromise(string: string): Promise<void>

return new Promise<void> ((resolve, reject) =>
setTimeout(
() =>
console.log(string)
resolve()
,
Math.floor(Math.random() * 100) + 1
)
)




Main.ts



import Printer from './Printer';


class App

public static run(): void

Printer.printStringWithPromise("A")
.then(() => Printer.printStringWithPromise("B"))
.then(() => Printer.printStringWithPromise("C"))




App.run();


Then I just run tsc src/Main.ts --outDir out/ and it throws at me the above-mentioned error. What am I doing wrong?










share|improve this question

















  • 2





    In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later.

    – jcalz
    Mar 8 at 17:40











  • @jcalz Well yeah I had to add the tsconfig file where I had to set the target field to es6 and then it's become possible to compile and run it with tsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js I wonder if it's possible to do without tsconfig and set all the required stuff in the command line.

    – ichweißnix
    Mar 8 at 17:56












  • you can use --target on the command line afaik

    – jcalz
    Mar 8 at 17:57











  • @jcalz Yeah I see now. It works.

    – ichweißnix
    Mar 8 at 18:02











  • @jcalz: Post as answer please.

    – H.B.
    Mar 9 at 0:37















0















Sort of trying to figure out how asynchronous stuff works in typescript and when I run my compiler it yields this error. Here is the code I'm trying to compile:



Printer.ts



export class Printer

public static printString(string: string, callback): void

setTimeout(
() =>
console.log(string)
callback()
,
Math.floor(Math.random() * 100) + 1
)


public static printStringWithPromise(string: string): Promise<void>

return new Promise<void> ((resolve, reject) =>
setTimeout(
() =>
console.log(string)
resolve()
,
Math.floor(Math.random() * 100) + 1
)
)




Main.ts



import Printer from './Printer';


class App

public static run(): void

Printer.printStringWithPromise("A")
.then(() => Printer.printStringWithPromise("B"))
.then(() => Printer.printStringWithPromise("C"))




App.run();


Then I just run tsc src/Main.ts --outDir out/ and it throws at me the above-mentioned error. What am I doing wrong?










share|improve this question

















  • 2





    In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later.

    – jcalz
    Mar 8 at 17:40











  • @jcalz Well yeah I had to add the tsconfig file where I had to set the target field to es6 and then it's become possible to compile and run it with tsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js I wonder if it's possible to do without tsconfig and set all the required stuff in the command line.

    – ichweißnix
    Mar 8 at 17:56












  • you can use --target on the command line afaik

    – jcalz
    Mar 8 at 17:57











  • @jcalz Yeah I see now. It works.

    – ichweißnix
    Mar 8 at 18:02











  • @jcalz: Post as answer please.

    – H.B.
    Mar 9 at 0:37













0












0








0








Sort of trying to figure out how asynchronous stuff works in typescript and when I run my compiler it yields this error. Here is the code I'm trying to compile:



Printer.ts



export class Printer

public static printString(string: string, callback): void

setTimeout(
() =>
console.log(string)
callback()
,
Math.floor(Math.random() * 100) + 1
)


public static printStringWithPromise(string: string): Promise<void>

return new Promise<void> ((resolve, reject) =>
setTimeout(
() =>
console.log(string)
resolve()
,
Math.floor(Math.random() * 100) + 1
)
)




Main.ts



import Printer from './Printer';


class App

public static run(): void

Printer.printStringWithPromise("A")
.then(() => Printer.printStringWithPromise("B"))
.then(() => Printer.printStringWithPromise("C"))




App.run();


Then I just run tsc src/Main.ts --outDir out/ and it throws at me the above-mentioned error. What am I doing wrong?










share|improve this question














Sort of trying to figure out how asynchronous stuff works in typescript and when I run my compiler it yields this error. Here is the code I'm trying to compile:



Printer.ts



export class Printer

public static printString(string: string, callback): void

setTimeout(
() =>
console.log(string)
callback()
,
Math.floor(Math.random() * 100) + 1
)


public static printStringWithPromise(string: string): Promise<void>

return new Promise<void> ((resolve, reject) =>
setTimeout(
() =>
console.log(string)
resolve()
,
Math.floor(Math.random() * 100) + 1
)
)




Main.ts



import Printer from './Printer';


class App

public static run(): void

Printer.printStringWithPromise("A")
.then(() => Printer.printStringWithPromise("B"))
.then(() => Printer.printStringWithPromise("C"))




App.run();


Then I just run tsc src/Main.ts --outDir out/ and it throws at me the above-mentioned error. What am I doing wrong?







typescript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 17:35









ichweißnixichweißnix

1




1







  • 2





    In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later.

    – jcalz
    Mar 8 at 17:40











  • @jcalz Well yeah I had to add the tsconfig file where I had to set the target field to es6 and then it's become possible to compile and run it with tsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js I wonder if it's possible to do without tsconfig and set all the required stuff in the command line.

    – ichweißnix
    Mar 8 at 17:56












  • you can use --target on the command line afaik

    – jcalz
    Mar 8 at 17:57











  • @jcalz Yeah I see now. It works.

    – ichweißnix
    Mar 8 at 18:02











  • @jcalz: Post as answer please.

    – H.B.
    Mar 9 at 0:37












  • 2





    In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later.

    – jcalz
    Mar 8 at 17:40











  • @jcalz Well yeah I had to add the tsconfig file where I had to set the target field to es6 and then it's become possible to compile and run it with tsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js I wonder if it's possible to do without tsconfig and set all the required stuff in the command line.

    – ichweißnix
    Mar 8 at 17:56












  • you can use --target on the command line afaik

    – jcalz
    Mar 8 at 17:57











  • @jcalz Yeah I see now. It works.

    – ichweißnix
    Mar 8 at 18:02











  • @jcalz: Post as answer please.

    – H.B.
    Mar 9 at 0:37







2




2





In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later.

– jcalz
Mar 8 at 17:40





In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later.

– jcalz
Mar 8 at 17:40













@jcalz Well yeah I had to add the tsconfig file where I had to set the target field to es6 and then it's become possible to compile and run it with tsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js I wonder if it's possible to do without tsconfig and set all the required stuff in the command line.

– ichweißnix
Mar 8 at 17:56






@jcalz Well yeah I had to add the tsconfig file where I had to set the target field to es6 and then it's become possible to compile and run it with tsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js I wonder if it's possible to do without tsconfig and set all the required stuff in the command line.

– ichweißnix
Mar 8 at 17:56














you can use --target on the command line afaik

– jcalz
Mar 8 at 17:57





you can use --target on the command line afaik

– jcalz
Mar 8 at 17:57













@jcalz Yeah I see now. It works.

– ichweißnix
Mar 8 at 18:02





@jcalz Yeah I see now. It works.

– ichweißnix
Mar 8 at 18:02













@jcalz: Post as answer please.

– H.B.
Mar 9 at 0:37





@jcalz: Post as answer please.

– H.B.
Mar 9 at 0:37












2 Answers
2






active

oldest

votes


















0














In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later. Good luck!






share|improve this answer






























    0














    By default, TypeScript includes only the es3 library during compilation, but promises only came with es6 (aka es2015). Thus, you'll have to include es6 in the tsconfig.json#compilerOptions#lib array - minimal example below.




    tsconfig.json




    "compilerOptions":
    "lib": ["es6"]
    ,
    "files": ["index.ts"]



    index.ts



    const prom = new Promise(resolve => resolve('hello world'));


    test script



    npm i typescript
    tsc # <- should not throw any error





    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55068274%2fpromise-only-refers-to-a-type-but-is-being-used-as-a-value-here%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later. Good luck!






      share|improve this answer



























        0














        In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later. Good luck!






        share|improve this answer

























          0












          0








          0







          In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later. Good luck!






          share|improve this answer













          In your tsconfig compiler options, check your --target and/or --lib. The Promise constructor only exists for ES2015 and later. Good luck!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 9 at 17:00









          jcalzjcalz

          30.3k22850




          30.3k22850























              0














              By default, TypeScript includes only the es3 library during compilation, but promises only came with es6 (aka es2015). Thus, you'll have to include es6 in the tsconfig.json#compilerOptions#lib array - minimal example below.




              tsconfig.json




              "compilerOptions":
              "lib": ["es6"]
              ,
              "files": ["index.ts"]



              index.ts



              const prom = new Promise(resolve => resolve('hello world'));


              test script



              npm i typescript
              tsc # <- should not throw any error





              share|improve this answer





























                0














                By default, TypeScript includes only the es3 library during compilation, but promises only came with es6 (aka es2015). Thus, you'll have to include es6 in the tsconfig.json#compilerOptions#lib array - minimal example below.




                tsconfig.json




                "compilerOptions":
                "lib": ["es6"]
                ,
                "files": ["index.ts"]



                index.ts



                const prom = new Promise(resolve => resolve('hello world'));


                test script



                npm i typescript
                tsc # <- should not throw any error





                share|improve this answer



























                  0












                  0








                  0







                  By default, TypeScript includes only the es3 library during compilation, but promises only came with es6 (aka es2015). Thus, you'll have to include es6 in the tsconfig.json#compilerOptions#lib array - minimal example below.




                  tsconfig.json




                  "compilerOptions":
                  "lib": ["es6"]
                  ,
                  "files": ["index.ts"]



                  index.ts



                  const prom = new Promise(resolve => resolve('hello world'));


                  test script



                  npm i typescript
                  tsc # <- should not throw any error





                  share|improve this answer















                  By default, TypeScript includes only the es3 library during compilation, but promises only came with es6 (aka es2015). Thus, you'll have to include es6 in the tsconfig.json#compilerOptions#lib array - minimal example below.




                  tsconfig.json




                  "compilerOptions":
                  "lib": ["es6"]
                  ,
                  "files": ["index.ts"]



                  index.ts



                  const prom = new Promise(resolve => resolve('hello world'));


                  test script



                  npm i typescript
                  tsc # <- should not throw any error






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 9 at 17:22

























                  answered Mar 9 at 17:09









                  Nino FiliuNino Filiu

                  2,87841428




                  2,87841428



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55068274%2fpromise-only-refers-to-a-type-but-is-being-used-as-a-value-here%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme