Typescript: Untyped function calls may not accept type arguments

Created on 10 Jan 2015  路  10Comments  路  Source: microsoft/TypeScript

The following code results in this error message:

mu.ts(52,10): error TS2347: Untyped function calls may not accept type arguments.

Why ?

class JsonRequest<T> {
    makePromise(request: https.RequestOptions): Promise<T> {
52:         return new Promise<T>(function(resolve, reject) {
Question

Most helpful comment

Great! As an explanation, the reason this happened is because we only try to fetch type information in the presence of an import directive, so the require on its own isn't sufficient.

All 10 comments

Generally you use type arguments if you want to have type safety. What would it mean to give T as a type argument to Promise if it's typed as any? Just any? Sure, that's somewhat intuitionistic even if any doesn't have type parameters - but didn't you give a type argument to get type safety? So it makes little sense.

Maybe you can explain your use case better - why isn't Promise just typed?

The JsonRequest is created like this:

var categoryJsonRequest = new JsonRequest<CategoryResult>();

Therefore I expected that I can use the generic type parameter to create a Promise of the given type (CategoryResult in this case).

BTW: the definition in the d.ts file looks like this

declare class Promise<R> implements Thenable<R> {
    constructor(callback: (resolve : (result?: R) => void, reject: (error: any) => void) => void);

BTW: The module is imported like this:

var Promise = require('es6-promise').Promise;

Ah, my apologies, I misunderstood your question - I thought your definition of Promise was typed as any.

I'm not able to reproduce this issue - have you tried using the compiler from our release-1.4 or master branches?

Just checked it with the latest release from master (message TS6029: Version 1.4.0.0). Same result.

Could you share more code? Also, what promises library are you using?

Replace

var Promise = require('es6-promise').Promise;

with

import es6PromiseLib = require('es6-promise');
var Promise = es6PromiseLib.Promise;

Let me know if that fixes your issue.

Yes it fixes my issue.

Great! As an explanation, the reason this happened is because we only try to fetch type information in the presence of an import directive, so the require on its own isn't sufficient.

Thanks a lot for the help and the explanation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uber5001 picture uber5001  路  3Comments

bgrieder picture bgrieder  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

wmaurer picture wmaurer  路  3Comments

manekinekko picture manekinekko  路  3Comments