-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Duplicate identifier 'Promise' (TS2529) too restrictive. #12323
Comments
For my current case, I'm able to get this working by: export interface Awaiter
{
(thisArg:any, _arguments:any[], P:PromiseConstructorLike, generator:Function):void;
}
export function awaiter(
thisArg:any,
_arguments:any[],
P:PromiseConstructorLike,
generator:Function)
{
if(!P) throw "Must provide Promise constructor. Try injecting Promise using awaiter.factory(PromiseConstructorLike).";
return new P((resolve, reject) =>
{
const g = generator = generator.apply(thisArg, _arguments);
step(g.next());
function fulfilled(value:any)
{
try
{ step(g.next(value)); }
catch(e)
{ reject(e); }
}
function rejected(value:any)
{
try
{ step(g["throw"](value)); }
catch(e)
{ reject(e); }
}
function step(result:any)
{
result.done
? resolve(result.value)
: new P(resolve => { resolve(result.value); }).then(fulfilled, rejected);
}
});
}
export module awaiter
{
export function factory(Promise:PromiseConstructorLike):Awaiter
{
return (thisArg:any, _arguments:any[], P:PromiseConstructorLike, generator:Function) =>
{
awaiter(thisArg, _arguments, P || Promise, generator);
};
}
} |
@yortus Ok that makes sense. And apparently this may change once generators are supported in es5? Ok, why not simply DI it like what I pasted above? I know what I have here isn't perfect, but it's working for me so it's possible that each module can decide it's own promise lib. |
There are two ways: 1. Polyfill
|
Ok, now I'm more interested how I can simply keep using my own helpers and not require a global reference. I've got this working the way I want at the moment, but now I'm getting:
|
Did you try |
I could do that but I'm not using es2015.promise. Does it end up just being a hack so I can ignore? |
Are you polyfilling If you are not using a global polyfill but importing some promise implementation locally, then I think you must either:
|
Well now that I've updated to 2.2 dev, it's gotten even weirder: |
Error:(8, 9) TS2529:Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions.
TypeScript Version: 2.1.1 (targeting ES5)
Code
What I'm confused about is when I look at the
__awaiter
code it expectsPromise
(P) to be available.In a modular environment, how else am I supposed to inject my own Promise lib so it can use it?
The text was updated successfully, but these errors were encountered: