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

TS 3.7: --declaration output for getter only property now is a getter instead of readonly #33939

Closed
mjbvz opened this issue Oct 10, 2019 · 30 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Oct 10, 2019

TypeScript Version: 3.7.0-dev.20191010

Search Terms:

  • --declaration
  • getter
  • d.ts

Repo:
For the TS file foo.ts:

export class Foo {
    get bar(): boolean { return true; }
}
  1. Run tsc foo.ts --declaration

Expected
In TS 3.6, the output d.ts uses readonly:

export declare class Foo {
    readonly bar: boolean;
}

Actual behavior:
In TS 3.7, the output d.ts use a getter instead:

export declare class Foo {
    get bar(): boolean;
}
@Jessidhia
Copy link

Jessidhia commented Oct 11, 2019

That is an intentional change done as part of #27644 that, it seems, was missed from the 3.7 blog post.

See also #33509 and #33880

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Oct 17, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@AndreasGassmann
Copy link

I just noticed this as well. The problem is that when I use our own library with the "getter-syntax", I get an error:

error TS1086: An accessor cannot be declared in an ambient context.

What is the recommended way of getting around that?

@matthiasg
Copy link

I have the same issue with 3.7 .. importing the types is now not possible

@AndreasGassmann
Copy link

@matthiasg It seems that they knew the typings were incompatible. I'm quite surprised that there was no mention of this anywhere (or did I overlook it?). #33470

I ended up writing a small script for our CI that replaces the new syntax with the old one as a temporary solution.

@GordonSmith
Copy link

GordonSmith commented Nov 9, 2019

This will prevent my library from upgrading to 3.7.x until all my customers are also using 3.7.x (and they include Angular folks who won't be upgrading Angular anytime soon).
Given this is a breaking change shouldn't it have waited until 4.x.x?

@paulquinn
Copy link

I'm also getting TS1086 when trying to use npm libraries with the "getter syntax" - could someone please give some guidance around this/can this be reopended?

@bcoe
Copy link

bcoe commented Nov 15, 2019

This seems like a fairly significant breaking change, and is biting a lot of our customer:

googleapis/node-gtoken#244

I understand it's working as intended, but I question why this was released in a minor release of the library, vs., a 4.x release like @GordonSmith mentions.

@paulquinn
Copy link

@RyanCavanaugh is there any other any guidance here (other than re-target to 3.6 or lower)? At least this should be documented somewhere... this is blocking up from using libraries compiled with 3.7 with our current Angular projects.

@endel
Copy link

endel commented Nov 29, 2019

Also having the same issue in an Angular project.

@bcrosnier
Copy link

Also got bit by the sudden breaking change through an Angular project (TS 3.5) referencing a library built by 3.7 with breaking definitions.

Solved by bashing the library provider until he rolled back to TS 3.6.

Just for reference, TS 3.7 support in Angular projects is handled by angular/angular-cli#16071.

@kamilmysliwiec
Copy link

Why is this issue closed? This PR should be reverted as soon as possible due to the breaking change it introduced. I can't update TS to 3.7+ in NestJS as well because people with TS 3.7 < won't be able to use it (see nestjs/nest#3513). The only existing solution is to downgrade TypeScript and don't use the latest version.

@robinsummerhill
Copy link

Why is this issue closed? This PR should be reverted as soon as possible due to the breaking change it introduced. I can't update TS to 3.7+ in NestJS as well because people with TS 3.7 < won't be able to use it (see nestjs/nest#3513). The only existing solution is to downgrade TypeScript and don't use the latest version.

I agree. This issue is causing major headaches throughout the library vendor community. The change should be opt-in and maybe tied to the new useDefineForClassFields option. Claiming that this is 'working as intended' does not help the library vendors that are now stuck on 3.6 because of this issue. I suspect that this side-effect was not planned and slipped through.

gms1 added a commit to gms1/jsonpointerx that referenced this issue Dec 7, 2019
@gms1
Copy link

gms1 commented Dec 7, 2019

@RyanCavanaugh
please do not intend to introduce any breaking changes in minor versions

@Gluups
Copy link

Gluups commented May 15, 2020

Pardon me if I did not assimilate the whole thread properly, but I saw the error message "An accessor cannot be declared in an ambient context" appeared when migrating from TS 3.6 to TS 3.7
Just after typing NPM UPDATE, I see that "tsc -v" answers "Version 3.1.2", and I still get that error message.
What version do you recommend me to downgrade to, and is there any direct way to do that or must I uninstall the product and reinstall it with a version number given ?
Or do you think the problem can be situated elsewhere ?
Angular CLI: 9.1.5
Node: 10.15.0
OS: win32 x64

Angular:
...
Ivy Workspace:

Package Version

@angular-devkit/architect 0.901.5
@angular-devkit/core 9.1.5
@angular-devkit/schematics 9.1.5
@schematics/angular 9.1.5
@schematics/update 0.901.5
rxjs 6.5.4

First, I read a bad information on Stackoverflow : tsc - v will not give you the version of TypeScript used in an Angular project, rather ask "ng version".
Well, I downgraded a few products, but still get "an accessor cannot be declared in an ambient context".
To downgrade, edit the version numbers in package.json, then close any tool that may be opened on the project including Visual Studio, and type "npm install".
Maybe I missed one ?
"@angular/cli": "~6.0.0", "@angular/compiler-cli": "~6.0.0", "ts-node": "~3.5.0", "typescript": "~3.5.0"

@rabomarnix
Copy link

rabomarnix commented May 15, 2020

@Gluups Don't think it's relevant to this issue, but you probably have [email protected] installed globally on your system. What version do you see if you do npx tsc -v?
You should either remove typescript globally or update it using npm i [email protected] -g or use npx tsc .. to grab your local typescript version.

If you still experience the error an accessor cannot be declared in an ambient context, then you have one or more dependencies which were released using typescript 3.7.. That's exactly the issue people are running into now.

@Gluups
Copy link

Gluups commented May 15, 2020

"npx tsc -v" tells me "3.5.3"
I have launched "npm i [email protected] -g" (it was quicker than I thought).
The number of errors has decreased to 148 when I launch the execution from Visual Studio, but I am afraid I still get the error "Impossible to declare an accessor in an ambient context".

package.json :
{
"name": "weather-client",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~9.1.6",
"@angular/common": "~9.1.6",
"@angular/compiler": "~9.1.6",
"@angular/core": "~9.1.6",
"@angular/forms": "~9.1.6",
"@angular/platform-browser": "~9.1.6",
"@angular/platform-browser-dynamic": "~9.1.6",
"@angular/router": "~9.1.6",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.5",
"@angular/cli": "~6.0.0",
"@angular/compiler-cli": "~6.0.0",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~3.5.0",
"tslint": "~6.1.0",
"typescript": "~3.5.0"
}
}


ng version :
@angular-devkit/architect 0.901.6
@angular-devkit/build-angular 0.901.6
@angular-devkit/build-optimizer 0.901.6
@angular-devkit/build-webpack 0.901.6
@angular-devkit/core 9.1.6
@angular-devkit/schematics 0.6.8
@angular/cli 6.0.8
@angular/compiler-cli 6.0.9
@ngtools/webpack 9.1.6
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.5.5
typescript 3.5.3
webpack 4.42.0

@Gluups
Copy link

Gluups commented May 15, 2020

If you still experience the error an accessor cannot be declared in an ambient context, then you have one or more dependencies which were released using typescript 3.7.. That's exactly the issue people are running into now.

Hum, that promises to be an adventure, does not it ? Anyway thank you for your answer.

@rabomarnix
Copy link

rabomarnix commented May 15, 2020

This is why typescript 3.7 does not produce not backwards-compatible typings imo. You need to upgrade to typescript 3.7 and the latest version of angular 9 which will work in your case I guess.

@Gluups
Copy link

Gluups commented May 15, 2020

I realize something. As the project already has worked properly, one reasonable solution is to restore package.json from the backup, and then run "npm install" -and surely not "npm update".
Supposing that when groping around to solve those errors you did not practice too many foolishnesses, that should work pretty quickly.
As a conclusion of this, if you have a source control, pay attention to include package.json in it.

Well, in the project there are some dependencies marked deprecated and others marked vulnerable, but this is another story -that can lead me back here of course.

@Driez
Copy link

Driez commented Oct 16, 2020

i guess breaking changes in minor versions are a new trend, are they now? Good job typescript team.... please get your stuff together and make stuff like this a major version upgrade next time....

djcsdy added a commit to djcsdy/DefinitelyTyped that referenced this issue Nov 20, 2020
The type definitions for postcss 8.x require this.

See: microsoft/TypeScript#33939
djcsdy added a commit to djcsdy/DefinitelyTyped that referenced this issue Nov 20, 2020
The type definitions for postcss 8.x require this.

See: microsoft/TypeScript#33939
djcsdy added a commit to djcsdy/DefinitelyTyped that referenced this issue Nov 20, 2020
The type definitions for postcss 8.x require this.

See: microsoft/TypeScript#33939
sandersn pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this issue Nov 21, 2020
* postcss-less: Update for v4.0

The only change in this version is to bump the dependency on postcss
to ^8.1.2.

* postcss-less: add ES2018.Promise

The type declarations for postcss 8.x require this.

* postcss-less: Set target: ES5.

The type definitions for postcss 8.x require this.

* postcss-less: Add self to authors.

* postcss-less: Set minimum TypeScript version: 3.7.

The type definitions for postcss 8.x require this.

See: microsoft/TypeScript#33939

* postcss-less: Update tests for postcss 8.x.
adumesny added a commit to gridstack/gridstack.js that referenced this issue Dec 4, 2020
* force Typescript 3.6.5 as >3.7 has getter breaking change forcing all
users of this lib to be >3.7 to compile.
* they should have made this a 4.x thing
see microsoft/TypeScript#33939
otherwise you get:
error TS1086: An accessor cannot be declared in an ambient context.
owenlow pushed a commit to owenlow/DefinitelyTyped that referenced this issue Dec 8, 2020
* postcss-less: Update for v4.0

The only change in this version is to bump the dependency on postcss
to ^8.1.2.

* postcss-less: add ES2018.Promise

The type declarations for postcss 8.x require this.

* postcss-less: Set target: ES5.

The type definitions for postcss 8.x require this.

* postcss-less: Add self to authors.

* postcss-less: Set minimum TypeScript version: 3.7.

The type definitions for postcss 8.x require this.

See: microsoft/TypeScript#33939

* postcss-less: Update tests for postcss 8.x.
dhilt added a commit to dhilt/vscroll that referenced this issue Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests