Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts] ////

//// [propertyAccessOnUnionWithGenericConditional.ts]
type InCommon = { common: string };

type CondWithAny<K extends string | number> =
K extends number ? any : { two: string };

type UnionWithAny<K extends string | number> =
InCommon | (CondWithAny<K> & InCommon);

function testWithAny<K extends string | number>(k: K) {
const val = {} as UnionWithAny<K>;
val.common;
}

//// [propertyAccessOnUnionWithGenericConditional.js]
function testWithAny(k) {
var val = {};
val.common;
}
Original file line number Diff line number Diff line change
@@ -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<K extends string | number> =
>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<K extends string | number> =
>UnionWithAny : Symbol(UnionWithAny, Decl(propertyAccessOnUnionWithGenericConditional.ts, 3, 43))
>K : Symbol(K, Decl(propertyAccessOnUnionWithGenericConditional.ts, 5, 18))

InCommon | (CondWithAny<K> & 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 extends string | number>(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<K>;
>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))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// [tests/cases/compiler/propertyAccessOnUnionWithGenericConditional.ts] ////

=== propertyAccessOnUnionWithGenericConditional.ts ===
type InCommon = { common: string };
>InCommon : InCommon
> : ^^^^^^^^
>common : string
> : ^^^^^^

type CondWithAny<K extends string | number> =
>CondWithAny : CondWithAny<K>
> : ^^^^^^^^^^^^^^

K extends number ? any : { two: string };
>two : string
> : ^^^^^^

type UnionWithAny<K extends string | number> =
>UnionWithAny : UnionWithAny<K>
> : ^^^^^^^^^^^^^^^

InCommon | (CondWithAny<K> & InCommon);

function testWithAny<K extends string | number>(k: K) {
>testWithAny : <K extends string | number>(k: K) => void
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^
>k : K
> : ^

const val = {} as UnionWithAny<K>;
>val : UnionWithAny<K>
> : ^^^^^^^^^^^^^^^
>{} as UnionWithAny<K> : UnionWithAny<K>
> : ^^^^^^^^^^^^^^^
>{} : {}
> : ^^

val.common;
>val.common : string
> : ^^^^^^
>val : UnionWithAny<K>
> : ^^^^^^^^^^^^^^^
>common : string
> : ^^^^^^
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type InCommon = { common: string };

type CondWithAny<K extends string | number> =
K extends number ? any : { two: string };

type UnionWithAny<K extends string | number> =
InCommon | (CondWithAny<K> & InCommon);

function testWithAny<K extends string | number>(k: K) {
const val = {} as UnionWithAny<K>;
val.common;
}
Loading