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

Webpack Build Errors: An accessor cannot be declared in an ambient context #46

Closed
douglasg14b opened this issue Jan 30, 2020 · 11 comments
Closed

Comments

@douglasg14b
Copy link

douglasg14b commented Jan 30, 2020

Expected Behavior

Project builds with webpack through Vue UI.

Current Behavior

It does not, it throws errors.

Steps to Reproduce

  1. Start a webpack/Vue Project
  2. Add this library
  3. Try to build

(Not sure if this is reproducible that way?)

Enviornment

TypeScript 3.5.3

 error  in [RedactedPath]/ClientApp/node_modules/ste-core/dist/dispatching.d.ts

ERROR in [RedactedPath]/ClientApp/node_modules/ste-core/dist/dispatching.d.ts
19:9 An accessor cannot be declared in an ambient context.
    17 |      * @memberOf DispatcherBase
    18 |      */
  > 19 |     get count(): number;
       |         ^
    20 |     /**
    21 |      * Subscribe to the event dispatcher.
    22 |      * @param fn The event handler that is called when the event is dispatched.

 error  in [RedactedPath]/ClientApp/node_modules/ste-core/dist/dispatching.d.ts

ERROR in [RedactedPath]/ClientApp/node_modules/ste-core/dist/dispatching.d.ts
119:9 An accessor cannot be declared in an ambient context.
    117 |      * @memberOf DispatcherWrapper
    118 |      */
  > 119 |     get count(): number;
        |         ^
    120 |     /**
    121 |      * Subscribe to the event dispatcher.
    122 |      * @param fn The event handler that is called when the event is dispatched.

 error  in [RedactedPath]/ClientApp/node_modules/ste-events/dist/events.d.ts

ERROR in [RedactedPath]/ClientApp/node_modules/ste-events/dist/events.d.ts
74:19 An accessor cannot be declared in an ambient context.
    72 |      * Gets the list with all the event dispatchers.
    73 |      */
  > 74 |     protected get events(): EventList<TSender, TArgs>;
       |                   ^
    75 |     /**
    76 |      * Subscribes to the event with the specified name.
    77 |      * @param name The name of the event.

 error  in [RedactedPath]/ClientApp/node_modules/ste-signals/dist/signals.d.ts

ERROR in [RedactedPath]/ClientApp/node_modules/ste-signals/dist/signals.d.ts
45:19 An accessor cannot be declared in an ambient context.
    43 | export declare abstract class SignalHandlingBase implements ISignalHandling {
    44 |     private _events;
  > 45 |     protected get events(): SignalList;
       |                   ^
    46 |     /**
    47 |      * Subscribes once to the event with the specified name.
    48 |      * @param name The name of the event.

 error  in [RedactedPath]/ClientApp/node_modules/ste-simple-events/dist/simple-events.d.ts

ERROR in [RedactedPath]/ClientApp/node_modules/ste-simple-events/dist/simple-events.d.ts
69:19 An accessor cannot be declared in an ambient context.
    67 | export declare abstract class SimpleEventHandlingBase<TArgs> implements ISimpleEventHandling<TArgs> {
    68 |     private _events;
  > 69 |     protected get events(): SimpleEventList<TArgs>;
       |                   ^
    70 |     /**
    71 |      * Subscribes to the event with the specified name.
    72 |      * @param name The name of the event.
@douglasg14b
Copy link
Author

Potentially related: https://stackoverflow.com/questions/59502139/ts1086-an-accessor-cannot-be-declared-in-an-ambient-context

Updating TypeScript to see if that resolves this. If it does, this library should make it clear that TS 3.6+ is a requirement.

@douglasg14b
Copy link
Author

Upgrading TypeScript resolved this issue.

@KeesCBakker
Copy link
Owner

That's a great find. Do we need to change something to the package? Or was upgrading your project enough?

@KeesCBakker
Copy link
Owner

I'll add a comment about being on 3.6+

@douglasg14b
Copy link
Author

douglasg14b commented Jan 30, 2020

I believe this should be corrected, as some may have issues upgrading to TS 3.6 or 3.7 if their dependencies don't support it.

I'm not sure what the issue is, but that SO issue is a good start.

@douglasg14b
Copy link
Author

douglasg14b commented Jan 30, 2020

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#class-field-mitigations

TS 3.7 introduced breaking changes incompatible with TS 3.5 or below, related to typings files I believe.

@mathiasi
Copy link

mathiasi commented Apr 12, 2020

I've just created a fresh AspNet Core project with Angular and I'm facing the same issue however I'm on TypeScript 3.8 so I'm not certain why it still isn't working for me:

Microsoft.AspNetCore.SpaServices: Error: ERROR in ../node_modules/ste-core/dist/dispatching.d.ts:19:9 - error TS1086: An accessor cannot be declared in an ambient context.

19     get count(): number;
           ~~~~~
../node_modules/ste-core/dist/dispatching.d.ts:119:9 - error TS1086: An accessor cannot be declared in an ambient context.

119     get count(): number;
            ~~~~~
../node_modules/ste-events/dist/events.d.ts:74:19 - error TS1086: An accessor cannot be declared in an ambient context.

74     protected get events(): EventList<TSender, TArgs>;
                     ~~~~~~
../node_modules/ste-signals/dist/signals.d.ts:45:19 - error TS1086: An accessor cannot be declared in an ambient context.

45     protected get events(): SignalList;
                     ~~~~~~
../node_modules/ste-simple-events/dist/simple-events.d.ts:69:19 - error TS1086: An accessor cannot be declared in an ambient context.

69     protected get events(): SimpleEventList<TArgs>;
                     ~~~~~~

Edit: using "strongly-typed-events": "1.6.11". I can add "skipLibCheck": true to my tsconfig.json but I would like to avoid that :)

@KeesCBakker
Copy link
Owner

@mathiasi, did you find a solution?

@mathiasi
Copy link

mathiasi commented Jun 9, 2020

@KeesCBakker Adding "skipLibCheck": true to tsconfig.json was my only solution but it seems more like a workaround :)

@KeesCBakker
Copy link
Owner

I read others converted

get count(): number;

to

readonly count: number

Might be an option for us as well, but I don't know if it messes the existing usages.

@KeesCBakker
Copy link
Owner

I'm closing the issue. The issue can be resolved by upgrading TypeScript. Thanks for participating guys.

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

3 participants