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

kendo.all.d.ts: kendo.data.transports has no index signature #4031

Closed
DaleyKD opened this issue Feb 27, 2018 · 11 comments
Closed

kendo.all.d.ts: kendo.data.transports has no index signature #4031

DaleyKD opened this issue Feb 27, 2018 · 11 comments

Comments

@DaleyKD
Copy link

DaleyKD commented Feb 27, 2018

Currently, kendo.all.d.ts shows the following for kendo.data.transports:

declare namespace kendo.data.transports {
    var odata: DataSourceTransport;
}

When trying to use the following code snippet:

type: (() => {
    if (kendo.data.transports['aspnetmvc-ajax']) {
        return 'aspnetmvc-ajax';
    } else {
        throw new Error('The kendo.aspnetmvc.min.js script is not included.');
    }
})(),

TypeScript tells me:

Element implicitly has an 'any' type because type 'typeof transports' has no index signature.

Kendo UI for jQuery version 2018.1.221.

@matanasov
Copy link
Contributor

matanasov commented Mar 6, 2018

@Stamo-Gochev @ag-petrov @ivanchev
Can you please take a look at this?

@matanasov
Copy link
Contributor

@DaleyKD
Could you please provide more details about this issue? We couldn't hit it locally so far.

@DaleyKD
Copy link
Author

DaleyKD commented Mar 6, 2018

I can try.

I'm in Visual Studio 2017, using TypeScript 2.7.2.

Fresh project. Only has all.ts and kendo.all.d.ts. This is my all.ts:

/// <reference path="kendo.all.d.ts" />

function kendoTest() {
    if (kendo.data.transports['aspnetmvc-ajax']) {
        return 'aspnetmvc-ajax';
    } else {
        throw new Error('The kendo.aspnetmvc.min.js script is not included.');
    }
}

This is the error in my Error List:

TS7017 (TS) Element implicitly has an 'any' type because type 'typeof transports' has no index signature.

Try setting noImplicitAny to true. I think this is the cause.

@matanasov
Copy link
Contributor

@DaleyKD
Thanks - indeed it is noImplicitAny causing the error.
Our developers will take a look at it and get back to you with the details.

@DaleyKD
Copy link
Author

DaleyKD commented Mar 23, 2020

Any update on this? It'd be nice to fix the index.d.ts so that you can use a proper indexer.

@ag-petrov
Copy link
Contributor

@DaleyKD This seems to be a general Typescript behavior. Could you please elaborate on how would you expect the declaration to be included in our typescript files?

@DaleyKD
Copy link
Author

DaleyKD commented Mar 26, 2020

I am no expert at TypeScript by any means, but looking at the way you guys extend kendo.data.transports like this:
image

...makes me think that there's a couple ways to do it. The simplest for today seems to be remove the declare namespace kendo.data.transports and instead moving it to be an interface under kendo.data:

declare namespace kendo.data {
    interface transports {
        odata: DataSourceTransport;
        [transportType: string]: DataSourceTransport;
    }
...

And that's not an exact type matching, since you also have RemoteTransport, LocalTransport and XmlaTransport (but you don't give us types for those).

I hope this gives some explanation as to where my mind is.

@DaleyKD
Copy link
Author

DaleyKD commented Mar 26, 2020

Well, that's not exactly right... that wouldn't work... but I hope it gives you a direction?

@DaleyKD
Copy link
Author

DaleyKD commented Mar 26, 2020

I guess after some deeper research, is it even possible to do this? Since you guys are saying it's a "namespace," but are using it more like some kind of static class.

microsoft/TypeScript#6480

I guess we can close this. I don't know if there's a solution other than to:

if ((kendo.data.transports as any)['aspnetmvc-ajax']) {
    return 'aspnetmvc-ajax';
} else {
    throw new Error('The kendo.aspnetmvc.min.js script is not included.');
}

I hate converting things to any. :(

@zdravkov
Copy link
Member

zdravkov commented Oct 8, 2020

Closing this for the moment because of the linked typescript issue that is still not addressed.

@zdravkov zdravkov closed this as completed Oct 8, 2020
@zdravkov zdravkov self-assigned this Oct 8, 2020
@DaleyKD
Copy link
Author

DaleyKD commented Nov 19, 2021

@zdravkov : Looks like that issue is now addressed, maybe even fixed? Can we reevaluate this issue now?

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

No branches or pull requests

5 participants