apazureck / odatatools

OData Tools for vscode
24 stars 12 forks source link

Namespace to Module? #16

Closed iqmeta closed 6 years ago

iqmeta commented 7 years ago

Can you change the generated code to export modules?

=> import * as Container from '../data/container'; always produces errors with Angular2 like => /src/data/container.ts' is not a module. => to import { MyProxy } from '../data/my-proxy';

As mentioned here http://stackoverflow.com/questions/32805559/typescript-es6-import-module-file-is-not-a-module-error there a lot's of problems with namespaces.

using the generated code directly without modifications using angluar cli giving a hard time because of this and webpack => Error: Uncaught (in promise): ReferenceError: odatatools is not defined

Kind regards.

apazureck commented 7 years ago

Sorry, had to have a look into it first.

That is a bug. I wrapped the namespace around the other classes / it is now generated from the metadata.

I won't have time the next week or so to do anything on that, so please work around it for now. I hope I can come out with a new release in April.

For completion and help for others:

Fix this by adding a export before the namespace or removing the namespace completely. TS will detect it as a model if an export is at the base:

>>>>export<<<< namespace MovieService {
    import ProxyBase = odatatools.ProxyBase;
    import EntitySet = odatatools.EntitySet;
    import ThenableCaller = odatatools.ThenableCaller;
    import Thenable = odatatools.Thenable;

    export class MovieContainer extends ProxyBase {
    ...

Then you can use it like this:

import {MovieService} from '../proxy/proxy';
import MovieContainer = MovieService.MovieContainer;

Thanks for the report

apazureck commented 7 years ago

Hi @iqmeta,

I hopefully fixed this in the recent version 1.0. I tested it using the ts compiler info, which said everything is ok so far.

Please note that the usage has changed. You can now select modular or ambient interface / proxy generation.

Please give me feedback, if it worked for you

iqmeta commented 7 years ago

Hey, thanks for all your effort. I have a look in the next days at it. Kind regards.

apazureck commented 6 years ago

@iqmeta: I hope everything is working so far. I'll close the issue. If it is still a problem let me know. Regards