forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(47595): allow using private fields in type queries (microsoft#47696
- Loading branch information
1 parent
3b95404
commit 063eaa7
Showing
6 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/privateNameInTypeQuery.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts(6,15): error TS2322: Type 'number' is not assignable to type 'string'. | ||
tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts(11,19): error TS18013: Property '#a' is not accessible outside class 'C' because it has a private identifier. | ||
|
||
|
||
==== tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts (2 errors) ==== | ||
class C { | ||
#a = 'a'; | ||
|
||
constructor() { | ||
const a: typeof this.#a = ''; // Ok | ||
const b: typeof this.#a = 1; // Error | ||
~ | ||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | ||
} | ||
} | ||
|
||
const c = new C(); | ||
const a: typeof c.#a = ''; | ||
~~ | ||
!!! error TS18013: Property '#a' is not accessible outside class 'C' because it has a private identifier. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//// [privateNameInTypeQuery.ts] | ||
class C { | ||
#a = 'a'; | ||
|
||
constructor() { | ||
const a: typeof this.#a = ''; // Ok | ||
const b: typeof this.#a = 1; // Error | ||
} | ||
} | ||
|
||
const c = new C(); | ||
const a: typeof c.#a = ''; | ||
|
||
|
||
//// [privateNameInTypeQuery.js] | ||
"use strict"; | ||
class C { | ||
#a = 'a'; | ||
constructor() { | ||
const a = ''; // Ok | ||
const b = 1; // Error | ||
} | ||
} | ||
const c = new C(); | ||
const a = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts === | ||
class C { | ||
>C : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) | ||
|
||
#a = 'a'; | ||
>#a : Symbol(C.#a, Decl(privateNameInTypeQuery.ts, 0, 9)) | ||
|
||
constructor() { | ||
const a: typeof this.#a = ''; // Ok | ||
>a : Symbol(a, Decl(privateNameInTypeQuery.ts, 4, 13)) | ||
>this.#a : Symbol(C.#a, Decl(privateNameInTypeQuery.ts, 0, 9)) | ||
>this : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) | ||
|
||
const b: typeof this.#a = 1; // Error | ||
>b : Symbol(b, Decl(privateNameInTypeQuery.ts, 5, 13)) | ||
>this.#a : Symbol(C.#a, Decl(privateNameInTypeQuery.ts, 0, 9)) | ||
>this : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) | ||
} | ||
} | ||
|
||
const c = new C(); | ||
>c : Symbol(c, Decl(privateNameInTypeQuery.ts, 9, 5)) | ||
>C : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) | ||
|
||
const a: typeof c.#a = ''; | ||
>a : Symbol(a, Decl(privateNameInTypeQuery.ts, 10, 5)) | ||
>c : Symbol(c, Decl(privateNameInTypeQuery.ts, 9, 5)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts === | ||
class C { | ||
>C : C | ||
|
||
#a = 'a'; | ||
>#a : string | ||
>'a' : "a" | ||
|
||
constructor() { | ||
const a: typeof this.#a = ''; // Ok | ||
>a : string | ||
>this.#a : string | ||
>this : this | ||
>'' : "" | ||
|
||
const b: typeof this.#a = 1; // Error | ||
>b : string | ||
>this.#a : string | ||
>this : this | ||
>1 : 1 | ||
} | ||
} | ||
|
||
const c = new C(); | ||
>c : C | ||
>new C() : C | ||
>C : typeof C | ||
|
||
const a: typeof c.#a = ''; | ||
>a : any | ||
>c.#a : any | ||
>c : C | ||
>'' : "" | ||
|
14 changes: 14 additions & 0 deletions
14
tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @strict: true | ||
// @target: esnext | ||
|
||
class C { | ||
#a = 'a'; | ||
|
||
constructor() { | ||
const a: typeof this.#a = ''; // Ok | ||
const b: typeof this.#a = 1; // Error | ||
} | ||
} | ||
|
||
const c = new C(); | ||
const a: typeof c.#a = ''; |