Skip to content

Commit

Permalink
🤖 Pick PR #58083 (Don't propagate partial union/inter...) into releas…
Browse files Browse the repository at this point in the history
…e-5.4 (#58136)

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
  • Loading branch information
TypeScript Bot and ahejlsberg authored Apr 9, 2024
1 parent 38a7c05 commit 892936f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14788,16 +14788,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// these partial properties when identifying discriminant properties, but otherwise they are filtered out
// and do not appear to be present in the union type.
function getUnionOrIntersectionProperty(type: UnionOrIntersectionType, name: __String, skipObjectFunctionPropertyAugment?: boolean): Symbol | undefined {
let property = type.propertyCacheWithoutObjectFunctionPropertyAugment?.get(name) ||
!skipObjectFunctionPropertyAugment ? type.propertyCache?.get(name) : undefined;
let property = skipObjectFunctionPropertyAugment ?
type.propertyCacheWithoutObjectFunctionPropertyAugment?.get(name) :
type.propertyCache?.get(name);
if (!property) {
property = createUnionOrIntersectionProperty(type, name, skipObjectFunctionPropertyAugment);
if (property) {
const properties = skipObjectFunctionPropertyAugment ?
type.propertyCacheWithoutObjectFunctionPropertyAugment ||= createSymbolTable() :
type.propertyCache ||= createSymbolTable();
properties.set(name, property);
if (skipObjectFunctionPropertyAugment && !type.propertyCache?.get(name)) {
// Propagate an entry from the non-augmented cache to the augmented cache unless the property is partial.
if (skipObjectFunctionPropertyAugment && !(getCheckFlags(property) & CheckFlags.Partial) && !type.propertyCache?.get(name)) {
const properties = type.propertyCache ||= createSymbolTable();
properties.set(name, property);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// <reference path="fourslash.ts" />

// @strict: true
// @lib: esnext

//// interface ComponentOptions<Props> {
//// setup?: (props: Props) => void;
//// name?: string;
//// }
////
//// interface FunctionalComponent<P> {
//// (props: P): void;
//// }
////
//// type ConcreteComponent<Props> =
//// | ComponentOptions<Props>
//// | FunctionalComponent<Props>;
////
//// type Component<Props = {}> = ConcreteComponent<Props>;
////
//// type WithInstallPlugin = { _prefix?: string };
////
////
//// /**/
//// export function withInstall<C extends Component, T extends WithInstallPlugin>(
//// component: C | C[],
//// target?: T,
//// ): string {
//// const componentWithInstall = (target ?? component) as T;
//// const components = Array.isArray(component) ? component : [component];
////
//// const { name } = components[0];
//// if (name) {
//// return name;
//// }
////
//// return "";
//// }

verify.noErrors();

goTo.marker();
edit.insert("type C = Component['name']");

verify.noErrors();

0 comments on commit 892936f

Please sign in to comment.