Skip to content
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

Can't use Deferred as a type #16

Closed
joejohndoe opened this issue May 3, 2016 · 6 comments
Closed

Can't use Deferred as a type #16

joejohndoe opened this issue May 3, 2016 · 6 comments
Labels

Comments

@joejohndoe
Copy link

Repro case

import Deferred = require("dojo/Deferred");

interface SomeInterface {
  dfd: Deferred<SomeType>;
  // ...
}

export function process(): IPromise<SomeType> {
  let dfd = new Deferred<SomeType>();
  // ...
  return dfd;
}

Problem

The repro case results in a TS2304: Cannot find name 'Deferred' compiler message for the usage of Deferred as type in the interface, but not for the usage as constructor in the function.

Solution

Changing the declaration Deferred in module.d.ts to

declare module 'dojo/_base/Deferred' {
    type Deferred = dojo._base.Deferred;
    const Deferred: dojo._base.DeferredConstructor;
    export = Deferred;
}

fixes the problem.

@kitsonk kitsonk added the bug label May 3, 2016
@kitsonk
Copy link
Member

kitsonk commented May 3, 2016

Correct, the typing is wrong.

@bitranch
Copy link
Member

bitranch commented May 3, 2016

The typings are namespaced, so your example could be fixed by simply adding the "dojo." namespace:

interface SomeInterface {
  dfd: dojo.Deferred<SomeType>;
}

@kitsonk
Copy link
Member

kitsonk commented May 3, 2016

@bitranch but what I didn't realise is you can merge the types too... which makes it handy! I learned something new.

@kitsonk kitsonk closed this as completed in 27126a5 May 3, 2016
@bitranch
Copy link
Member

bitranch commented May 3, 2016

True. But since he's importing from 'dojo/Deferred' setting the type in 'dojo/_base/Deferred' might not fix this particular issue.

@kitsonk
Copy link
Member

kitsonk commented May 3, 2016

True... the change I pushed was related to what he mentioned he imported. Didn't realise he was importing from one but referring to another.

@kitsonk
Copy link
Member

kitsonk commented May 4, 2016

Ok, I have rolled this out to I think everything we currently have in the repo that it applies to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants