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

                      Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                      Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                      How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page