Skip to content

Commit 892936f

Browse files
TypeScript Botahejlsberg
andauthored
🤖 Pick PR #58083 (Don't propagate partial union/inter...) into release-5.4 (#58136)
Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
1 parent 38a7c05 commit 892936f

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

‎src/compiler/checker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14788,16 +14788,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1478814788
// these partial properties when identifying discriminant properties, but otherwise they are filtered out
1478914789
// and do not appear to be present in the union type.
1479014790
function getUnionOrIntersectionProperty(type: UnionOrIntersectionType, name: __String, skipObjectFunctionPropertyAugment?: boolean): Symbol | undefined {
14791-
let property = type.propertyCacheWithoutObjectFunctionPropertyAugment?.get(name) ||
14792-
!skipObjectFunctionPropertyAugment ? type.propertyCache?.get(name) : undefined;
14791+
let property = skipObjectFunctionPropertyAugment ?
14792+
type.propertyCacheWithoutObjectFunctionPropertyAugment?.get(name) :
14793+
type.propertyCache?.get(name);
1479314794
if (!property) {
1479414795
property = createUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment);
1479514796
if (property) {
1479614797
const properties = skipObjectFunctionPropertyAugment ?
1479714798
type.propertyCacheWithoutObjectFunctionPropertyAugment ||= createSymbolTable() :
1479814799
type.propertyCache ||= createSymbolTable();
1479914800
properties.set(name, property);
14800-
if (skipObjectFunctionPropertyAugment && !type.propertyCache?.get(name)) {
14801+
// Propagate an entry from the non-augmented cache to the augmented cache unless the property is partial.
14802+
if (skipObjectFunctionPropertyAugment && !(getCheckFlags(property) & CheckFlags.Partial) && !type.propertyCache?.get(name)) {
1480114803
const properties = type.propertyCache ||= createSymbolTable();
1480214804
properties.set(name, property);
1480314805
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strict: true
4+
// @lib: esnext
5+
6+
//// interface ComponentOptions<Props> {
7+
//// setup?: (props: Props) => void;
8+
//// name?: string;
9+
//// }
10+
////
11+
//// interface FunctionalComponent<P> {
12+
//// (props: P): void;
13+
//// }
14+
////
15+
//// type ConcreteComponent<Props> =
16+
//// | ComponentOptions<Props>
17+
//// | FunctionalComponent<Props>;
18+
////
19+
//// type Component<Props = {}> = ConcreteComponent<Props>;
20+
////
21+
//// type WithInstallPlugin = { _prefix?: string };
22+
////
23+
////
24+
//// /**/
25+
//// export function withInstall<C extends Component, T extends WithInstallPlugin>(
26+
//// component: C | C[],
27+
//// target?: T,
28+
//// ): string {
29+
//// const componentWithInstall = (target ?? component) as T;
30+
//// const components = Array.isArray(component) ? component : [component];
31+
////
32+
//// const { name } = components[0];
33+
//// if (name) {
34+
//// return name;
35+
//// }
36+
////
37+
//// return "";
38+
//// }
39+
40+
verify.noErrors();
41+
42+
goTo.marker();
43+
edit.insert("type C = Component['name']");
44+
45+
verify.noErrors();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy