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.”
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
add a comment |
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
2
In your tsconfig compiler options, check your--target
and/or--lib
. ThePromise
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 thetarget
field toes6
and then it's become possible to compile and run it withtsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js
I wonder if it's possible to do withouttsconfig
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
add a comment |
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
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
typescript
asked Mar 8 at 17:35
ichweißnixichweißnix
1
1
2
In your tsconfig compiler options, check your--target
and/or--lib
. ThePromise
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 thetarget
field toes6
and then it's become possible to compile and run it withtsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js
I wonder if it's possible to do withouttsconfig
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
add a comment |
2
In your tsconfig compiler options, check your--target
and/or--lib
. ThePromise
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 thetarget
field toes6
and then it's become possible to compile and run it withtsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js
I wonder if it's possible to do withouttsconfig
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
add a comment |
2 Answers
2
active
oldest
votes
In your tsconfig compiler options, check your --target
and/or --lib
. The Promise
constructor only exists for ES2015 and later. Good luck!
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
In your tsconfig compiler options, check your --target
and/or --lib
. The Promise
constructor only exists for ES2015 and later. Good luck!
add a comment |
In your tsconfig compiler options, check your --target
and/or --lib
. The Promise
constructor only exists for ES2015 and later. Good luck!
add a comment |
In your tsconfig compiler options, check your --target
and/or --lib
. The Promise
constructor only exists for ES2015 and later. Good luck!
In your tsconfig compiler options, check your --target
and/or --lib
. The Promise
constructor only exists for ES2015 and later. Good luck!
answered Mar 9 at 17:00
jcalzjcalz
30.3k22850
30.3k22850
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Mar 9 at 17:22
answered Mar 9 at 17:09
Nino FiliuNino Filiu
2,87841428
2,87841428
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
In your tsconfig compiler options, check your
--target
and/or--lib
. ThePromise
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 toes6
and then it's become possible to compile and run it withtsc --project PATH_TO_PROJECT --outDir PATH_TO_OUTDIR && nodejs PATH_TO_OUTDIR/Main.js
I wonder if it's possible to do withouttsconfig
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