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

🤖 Cherry-pick PR #37021 into release-3.8 #37025

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16153,6 +16153,7 @@ namespace ts {
if (unmatchedProperty.valueDeclaration
&& isNamedDeclaration(unmatchedProperty.valueDeclaration)
&& isPrivateIdentifier(unmatchedProperty.valueDeclaration.name)
&& source.symbol
&& source.symbol.flags & SymbolFlags.Class) {
const privateIdentifierDescription = unmatchedProperty.valueDeclaration.name.escapedText;
const symbolTableKey = getSymbolNameForPrivateIdentifier(source.symbol, privateIdentifierDescription);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts(2,3): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts(5,7): error TS2741: Property '#field' is missing in type '{}' but required in type 'Class'.


==== tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts (2 errors) ====
export class Class {
#field: any
~~~~~~
!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
}

const task: Class = {} as unknown;
~~~~
!!! error TS2741: Property '#field' is missing in type '{}' but required in type 'Class'.
!!! related TS2728 tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts:2:3: '#field' is declared here.

21 changes: 21 additions & 0 deletions tests/baselines/reference/privateFieldAssignabilityFromUnknown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [privateFieldAssignabilityFromUnknown.ts]
export class Class {
#field: any
}

const task: Class = {} as unknown;


//// [privateFieldAssignabilityFromUnknown.js]
"use strict";
var _field;
exports.__esModule = true;
var Class = /** @class */ (function () {
function Class() {
_field.set(this, void 0);
}
return Class;
}());
exports.Class = Class;
_field = new WeakMap();
var task = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts ===
export class Class {
>Class : Symbol(Class, Decl(privateFieldAssignabilityFromUnknown.ts, 0, 0))

#field: any
>#field : Symbol(Class.#field, Decl(privateFieldAssignabilityFromUnknown.ts, 0, 20))
}

const task: Class = {} as unknown;
>task : Symbol(task, Decl(privateFieldAssignabilityFromUnknown.ts, 4, 5))
>Class : Symbol(Class, Decl(privateFieldAssignabilityFromUnknown.ts, 0, 0))

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts ===
export class Class {
>Class : Class

#field: any
>#field : any
}

const task: Class = {} as unknown;
>task : Class
>{} as unknown : unknown
>{} : {}

5 changes: 5 additions & 0 deletions tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class Class {
#field: any
}

const task: Class = {} as unknown;