-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handle private/protected members in unions of object types (#…
…38277) (#38334) * Property handle private/protected properties in unions of object types * Add regression test Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
- Loading branch information
1 parent
e261cdd
commit b7d3459
Showing
5 changed files
with
112 additions
and
10 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
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,24 @@ | ||
//// [privatePropertyInUnion.ts] | ||
// Repro from #38236 | ||
|
||
type Type = string | object; | ||
|
||
class SyncableObject { | ||
private foo: unknown; | ||
} | ||
|
||
interface SyncableRef<T extends ISyncableObject> {} | ||
|
||
interface ISyncableObject<T = object> extends SyncableObject {} | ||
|
||
type __ValueDescriptorType<T extends string | object> = T extends ISyncableObject ? SyncableRef<T> : T; | ||
|
||
|
||
//// [privatePropertyInUnion.js] | ||
"use strict"; | ||
// Repro from #38236 | ||
var SyncableObject = /** @class */ (function () { | ||
function SyncableObject() { | ||
} | ||
return SyncableObject; | ||
}()); |
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,32 @@ | ||
=== tests/cases/compiler/privatePropertyInUnion.ts === | ||
// Repro from #38236 | ||
|
||
type Type = string | object; | ||
>Type : Symbol(Type, Decl(privatePropertyInUnion.ts, 0, 0)) | ||
|
||
class SyncableObject { | ||
>SyncableObject : Symbol(SyncableObject, Decl(privatePropertyInUnion.ts, 2, 28)) | ||
|
||
private foo: unknown; | ||
>foo : Symbol(SyncableObject.foo, Decl(privatePropertyInUnion.ts, 4, 22)) | ||
} | ||
|
||
interface SyncableRef<T extends ISyncableObject> {} | ||
>SyncableRef : Symbol(SyncableRef, Decl(privatePropertyInUnion.ts, 6, 1)) | ||
>T : Symbol(T, Decl(privatePropertyInUnion.ts, 8, 22)) | ||
>ISyncableObject : Symbol(ISyncableObject, Decl(privatePropertyInUnion.ts, 8, 51)) | ||
|
||
interface ISyncableObject<T = object> extends SyncableObject {} | ||
>ISyncableObject : Symbol(ISyncableObject, Decl(privatePropertyInUnion.ts, 8, 51)) | ||
>T : Symbol(T, Decl(privatePropertyInUnion.ts, 10, 26)) | ||
>SyncableObject : Symbol(SyncableObject, Decl(privatePropertyInUnion.ts, 2, 28)) | ||
|
||
type __ValueDescriptorType<T extends string | object> = T extends ISyncableObject ? SyncableRef<T> : T; | ||
>__ValueDescriptorType : Symbol(__ValueDescriptorType, Decl(privatePropertyInUnion.ts, 10, 63)) | ||
>T : Symbol(T, Decl(privatePropertyInUnion.ts, 12, 27)) | ||
>T : Symbol(T, Decl(privatePropertyInUnion.ts, 12, 27)) | ||
>ISyncableObject : Symbol(ISyncableObject, Decl(privatePropertyInUnion.ts, 8, 51)) | ||
>SyncableRef : Symbol(SyncableRef, Decl(privatePropertyInUnion.ts, 6, 1)) | ||
>T : Symbol(T, Decl(privatePropertyInUnion.ts, 12, 27)) | ||
>T : Symbol(T, Decl(privatePropertyInUnion.ts, 12, 27)) | ||
|
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,20 @@ | ||
=== tests/cases/compiler/privatePropertyInUnion.ts === | ||
// Repro from #38236 | ||
|
||
type Type = string | object; | ||
>Type : string | object | ||
|
||
class SyncableObject { | ||
>SyncableObject : SyncableObject | ||
|
||
private foo: unknown; | ||
>foo : unknown | ||
} | ||
|
||
interface SyncableRef<T extends ISyncableObject> {} | ||
|
||
interface ISyncableObject<T = object> extends SyncableObject {} | ||
|
||
type __ValueDescriptorType<T extends string | object> = T extends ISyncableObject ? SyncableRef<T> : T; | ||
>__ValueDescriptorType : __ValueDescriptorType<T> | ||
|
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,15 @@ | ||
// @strict: true | ||
|
||
// Repro from #38236 | ||
|
||
type Type = string | object; | ||
|
||
class SyncableObject { | ||
private foo: unknown; | ||
} | ||
|
||
interface SyncableRef<T extends ISyncableObject> {} | ||
|
||
interface ISyncableObject<T = object> extends SyncableObject {} | ||
|
||
type __ValueDescriptorType<T extends string | object> = T extends ISyncableObject ? SyncableRef<T> : T; |