diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 664fe44caf95e..75fc76fda4257 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15496,7 +15496,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let mergedInstantiations = false; for (const current of containingType.types) { const type = getApparentType(current); - if (!(isErrorType(type) || type.flags & TypeFlags.Never)) { + if (!(isErrorType(type) || type.flags & TypeFlags.Never || type.flags & TypeFlags.Any)) { const prop = getPropertyOfType(type, name, skipObjectFunctionPropertyAugment); const modifiers = prop ? getDeclarationModifierFlagsFromSymbol(prop) : 0; if (prop) { diff --git a/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.js b/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.js new file mode 100644 index 0000000000000..621091144a5d6 --- /dev/null +++ b/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts] //// + +//// [propertyAccessOnUnionWithGenericConditional.ts] +type InCommon = { common: string }; + +type CondWithAny = + K extends number ? any : { two: string }; + +type UnionWithAny = + InCommon | (CondWithAny & InCommon); + +function testWithAny(k: K) { + const val = {} as UnionWithAny; + val.common; +} + +//// [propertyAccessOnUnionWithGenericConditional.js] +function testWithAny(k) { + var val = {}; + val.common; +} diff --git a/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.symbols b/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.symbols new file mode 100644 index 0000000000000..d4e9684d114a9 --- /dev/null +++ b/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.symbols @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts] //// + +=== propertyAccessOnUnionWithGenericConditional.ts === +type InCommon = { common: string }; +>InCommon : Symbol(InCommon, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 0)) +>common : Symbol(common, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 17)) + +type CondWithAny = +>CondWithAny : Symbol(CondWithAny, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 35)) +>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 2, 17)) + + K extends number ? any : { two: string }; +>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 2, 17)) +>two : Symbol(two, Decl(propertyAccessOnUnionWithGenericConditional.ts, 3, 28)) + +type UnionWithAny = +>UnionWithAny : Symbol(UnionWithAny, Decl(propertyAccessOnUnionWithGenericConditional.ts, 3, 43)) +>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 5, 18)) + + InCommon | (CondWithAny & InCommon); +>InCommon : Symbol(InCommon, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 0)) +>CondWithAny : Symbol(CondWithAny, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 35)) +>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 5, 18)) +>InCommon : Symbol(InCommon, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 0)) + +function testWithAny(k: K) { +>testWithAny : Symbol(testWithAny, Decl(propertyAccessOnUnionWithGenericConditional.ts, 6, 41)) +>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 8, 21)) +>k : Symbol(k, Decl(propertyAccessOnUnionWithGenericConditional.ts, 8, 48)) +>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 8, 21)) + + const val = {} as UnionWithAny; +>val : Symbol(val, Decl(propertyAccessOnUnionWithGenericConditional.ts, 9, 7)) +>UnionWithAny : Symbol(UnionWithAny, Decl(propertyAccessOnUnionWithGenericConditional.ts, 3, 43)) +>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 8, 21)) + + val.common; +>val.common : Symbol(common, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 17)) +>val : Symbol(val, Decl(propertyAccessOnUnionWithGenericConditional.ts, 9, 7)) +>common : Symbol(common, Decl(propertyAccessOnUnionWithGenericConditional.ts, 0, 17)) +} diff --git a/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.types b/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.types new file mode 100644 index 0000000000000..eba7ab208e1c0 --- /dev/null +++ b/tests/baselines/reference/propertyAccessOnUnionWithGenericConditional.types @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts] //// + +=== propertyAccessOnUnionWithGenericConditional.ts === +type InCommon = { common: string }; +>InCommon : InCommon +> : ^^^^^^^^ +>common : string +> : ^^^^^^ + +type CondWithAny = +>CondWithAny : CondWithAny +> : ^^^^^^^^^^^^^^ + + K extends number ? any : { two: string }; +>two : string +> : ^^^^^^ + +type UnionWithAny = +>UnionWithAny : UnionWithAny +> : ^^^^^^^^^^^^^^^ + + InCommon | (CondWithAny & InCommon); + +function testWithAny(k: K) { +>testWithAny : (k: K) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^ +>k : K +> : ^ + + const val = {} as UnionWithAny; +>val : UnionWithAny +> : ^^^^^^^^^^^^^^^ +>{} as UnionWithAny : UnionWithAny +> : ^^^^^^^^^^^^^^^ +>{} : {} +> : ^^ + + val.common; +>val.common : string +> : ^^^^^^ +>val : UnionWithAny +> : ^^^^^^^^^^^^^^^ +>common : string +> : ^^^^^^ +} diff --git a/tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts b/tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts new file mode 100644 index 0000000000000..a4171b3e2baef --- /dev/null +++ b/tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts @@ -0,0 +1,12 @@ +type InCommon = { common: string }; + +type CondWithAny = + K extends number ? any : { two: string }; + +type UnionWithAny = + InCommon | (CondWithAny & InCommon); + +function testWithAny(k: K) { + const val = {} as UnionWithAny; + val.common; +} \ No newline at end of file