diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 91346429b1774..321e12c4d2a5e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31672,33 +31672,106 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return !!(getCheckFlags(symbol) & CheckFlags.Mapped && !(symbol as MappedSymbol).links.type && findResolutionCycleStartIndex(symbol, TypeSystemPropertyName.Type) >= 0); } + function isExcludedMappedPropertyName(constraint: Type, propertyNameType: Type): boolean { + if (constraint.flags & TypeFlags.Conditional) { + const type = constraint as ConditionalType; + return !!(getReducedType(getTrueTypeFromConditionalType(type)).flags & TypeFlags.Never) && + getActualTypeVariable(getFalseTypeFromConditionalType(type)) === getActualTypeVariable(type.checkType) && + isTypeAssignableTo(propertyNameType, type.extendsType); + } + if (constraint.flags & TypeFlags.Intersection) { + return some((constraint as IntersectionType).types, t => isExcludedMappedPropertyName(t, propertyNameType)); + } + return false; + } + function getTypeOfPropertyOfContextualType(type: Type, name: __String, nameType?: Type) { return mapType(type, t => { - if (isGenericMappedType(t) && getMappedTypeNameTypeKind(t) !== MappedTypeNameTypeKind.Remapping) { - const constraint = getConstraintTypeFromMappedType(t); - const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint; - const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name)); - if (isTypeAssignableTo(propertyNameType, constraintOfConstraint)) { - return substituteIndexedMappedType(t, propertyNameType); - } - } - else if (t.flags & TypeFlags.StructuredType) { - const prop = getPropertyOfType(t, name); - if (prop) { - return isCircularMappedProperty(prop) ? undefined : removeMissingType(getTypeOfSymbol(prop), !!(prop.flags & SymbolFlags.Optional)); + if (t.flags & TypeFlags.Intersection) { + let types: Type[] | undefined; + let indexInfoCandidates: Type[] | undefined; + let ignoreIndexInfos = false; + for (const constituentType of (t as IntersectionType).types) { + if (!(constituentType.flags & TypeFlags.Object)) { + continue; + } + if (isGenericMappedType(constituentType) && getMappedTypeNameTypeKind(constituentType) !== MappedTypeNameTypeKind.Remapping) { + const substitutedType = getIndexedMappedTypeSubstitutedTypeOfContextualType(constituentType, name, nameType); + types = appendContextualPropertyTypeConstituent(types, substitutedType); + continue; + } + const propertyType = getTypeOfConcretePropertyOfContextualType(constituentType, name); + if (!propertyType) { + if (!ignoreIndexInfos) { + indexInfoCandidates = append(indexInfoCandidates, constituentType); + } + continue; + } + ignoreIndexInfos = true; + indexInfoCandidates = undefined; + types = appendContextualPropertyTypeConstituent(types, propertyType); } - if (isTupleType(t) && isNumericLiteralName(name) && +name >= 0) { - const restType = getElementTypeOfSliceOfTupleType(t, t.target.fixedLength, /*endSkipCount*/ 0, /*writing*/ false, /*noReductions*/ true); - if (restType) { - return restType; + if (indexInfoCandidates) { + for (const candidate of indexInfoCandidates) { + const indexInfoType = getTypeFromIndexInfosOfContextualType(candidate, name, nameType); + types = appendContextualPropertyTypeConstituent(types, indexInfoType); } } - return findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type; + if (!types) { + return; + } + if (types.length === 1) { + return types[0]; + } + return getIntersectionType(types); } - return undefined; + if (!(t.flags & TypeFlags.Object)) { + return; + } + return isGenericMappedType(t) && getMappedTypeNameTypeKind(t) !== MappedTypeNameTypeKind.Remapping + ? getIndexedMappedTypeSubstitutedTypeOfContextualType(t, name, nameType) + : getTypeOfConcretePropertyOfContextualType(t, name) ?? getTypeFromIndexInfosOfContextualType(t, name, nameType); }, /*noReductions*/ true); } + function appendContextualPropertyTypeConstituent(types: Type[] | undefined, type: Type | undefined) { + // any doesn't provide any contextual information but could spoil the overall result by nullifying contextual information provided by other intersection constituents + // so it gets replaced with `unknown` as `T & unknown` is just `T` and all types computed based on the contextual information provided by other constituens are still assignable to any + return type ? append(types, type.flags & TypeFlags.Any ? unknownType : type) : types; + } + + function getIndexedMappedTypeSubstitutedTypeOfContextualType(type: MappedType, name: __String, nameType: Type | undefined) { + const propertyNameType = nameType || getStringLiteralType(unescapeLeadingUnderscores(name)); + const constraint = getConstraintTypeFromMappedType(type); + // special case for conditional types pretending to be negated types + if (type.nameType && isExcludedMappedPropertyName(type.nameType, propertyNameType) || isExcludedMappedPropertyName(constraint, propertyNameType)) { + return; + } + const constraintOfConstraint = getBaseConstraintOfType(constraint) || constraint; + if (!isTypeAssignableTo(propertyNameType, constraintOfConstraint)) { + return; + } + return substituteIndexedMappedType(type, propertyNameType); + } + + function getTypeOfConcretePropertyOfContextualType(type: Type, name: __String) { + const prop = getPropertyOfType(type, name); + if (!prop || isCircularMappedProperty(prop)) { + return; + } + return removeMissingType(getTypeOfSymbol(prop), !!(prop.flags & SymbolFlags.Optional)); + } + + function getTypeFromIndexInfosOfContextualType(type: Type, name: __String, nameType: Type | undefined) { + if (isTupleType(type) && isNumericLiteralName(name) && +name >= 0) { + const restType = getElementTypeOfSliceOfTupleType(type, type.target.fixedLength, /*endSkipCount*/ 0, /*writing*/ false, /*noReductions*/ true); + if (restType) { + return restType; + } + } + return findApplicableIndexInfo(getIndexInfosOfStructuredType(type), nameType || getStringLiteralType(unescapeLeadingUnderscores(name)))?.type; + } + // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of // the matching property in T, if one exists. Otherwise, it is the type of the numeric index signature in T, if one // exists. Otherwise, it is the type of the string index signature in T, if one exists. diff --git a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.errors.txt b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.errors.txt new file mode 100644 index 0000000000000..0c45d770b1dad --- /dev/null +++ b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.errors.txt @@ -0,0 +1,55 @@ +contextualPropertyOfGenericFilteringMappedType.ts(38,5): error TS2353: Object literal may only specify known properties, and 'foo' does not exist in type '{ bar: (value: string, prop: "bar") => void; }'. +contextualPropertyOfGenericFilteringMappedType.ts(38,11): error TS7006: Parameter 'value' implicitly has an 'any' type. +contextualPropertyOfGenericFilteringMappedType.ts(38,18): error TS7006: Parameter 'key' implicitly has an 'any' type. + + +==== contextualPropertyOfGenericFilteringMappedType.ts (3 errors) ==== + declare function f1( + data: T, + handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void }, + ): void; + + f1( + { + foo: 0, + bar: "", + }, + { + foo: (value, key) => {}, + bar: (value, key) => {}, + }, + ); + + declare function f2( + data: T, + handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void }, + ): void; + + f2( + { + foo: 0, + bar: "", + }, + { + bar: (value, key) => {}, + }, + ); + + f2( + { + foo: 0, + bar: "", + }, + { + foo: (value, key) => { + ~~~ +!!! error TS2353: Object literal may only specify known properties, and 'foo' does not exist in type '{ bar: (value: string, prop: "bar") => void; }'. + ~~~~~ +!!! error TS7006: Parameter 'value' implicitly has an 'any' type. + ~~~ +!!! error TS7006: Parameter 'key' implicitly has an 'any' type. + // implicit `any`s + }, + }, + ); + \ No newline at end of file diff --git a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols index 5bcaba07ec255..a49b80fcfc9d9 100644 --- a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols +++ b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols @@ -88,3 +88,24 @@ f2( }, ); +f2( +>f2 : Symbol(f2, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 14, 2)) + { + foo: 0, +>foo : Symbol(foo, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 32, 3)) + + bar: "", +>bar : Symbol(bar, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 33, 11)) + + }, + { + foo: (value, key) => { +>foo : Symbol(foo, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 36, 3)) +>value : Symbol(value, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 37, 10)) +>key : Symbol(key, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 37, 16)) + + // implicit `any`s + }, + }, +); + diff --git a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types index b55c98f6f650f..dd7dd68b0f8c8 100644 --- a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types +++ b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types @@ -125,3 +125,44 @@ f2( }, ); +f2( +>f2( { foo: 0, bar: "", }, { foo: (value, key) => { // implicit `any`s }, },) : void +> : ^^^^ +>f2 : (data: T, handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void; }) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ + { +>{ foo: 0, bar: "", } : { foo: number; bar: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + foo: 0, +>foo : number +> : ^^^^^^ +>0 : 0 +> : ^ + + bar: "", +>bar : string +> : ^^^^^^ +>"" : "" +> : ^^ + + }, + { +>{ foo: (value, key) => { // implicit `any`s }, } : { foo: (value: any, key: any) => void; } +> : ^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^^^^ + + foo: (value, key) => { +>foo : (value: any, key: any) => void +> : ^ ^^^^^^^ ^^^^^^^^^^^^^^ +>(value, key) => { // implicit `any`s } : (value: any, key: any) => void +> : ^ ^^^^^^^ ^^^^^^^^^^^^^^ +>value : any +> : ^^^ +>key : any +> : ^^^ + + // implicit `any`s + }, + }, +); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.symbols b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.symbols new file mode 100644 index 0000000000000..3b959ad27842b --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.symbols @@ -0,0 +1,114 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts === +type ComponentType

= (p: P) => any; +>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) +>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 19)) +>p : Symbol(p, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 25)) +>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 19)) + +type ComponentProps = C extends ComponentType ? P : never; +>ComponentProps : Symbol(ComponentProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 38)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 20)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 20)) +>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) +>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 54)) +>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 54)) + +type Attrs> = A; +>Attrs : Symbol(Attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 70)) +>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 11)) +>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 13)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>P : Symbol(P, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 11)) +>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 13)) + +interface StyledFunction< +>StyledFunction : Symbol(StyledFunction, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 40)) + + C extends ComponentType, +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) +>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) + + O extends object = {}, +>O : Symbol(O, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 6, 31)) + + A extends keyof any = never, +>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 7, 24)) + +> { + attrs< +>attrs : Symbol(StyledFunction.attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 9, 3)) + + U, +>U : Symbol(U, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 10, 8)) + + NewA extends Partial & U> & { +>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>ComponentProps : Symbol(ComponentProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 38)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) +>U : Symbol(U, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 10, 8)) + + [others: string]: any; +>others : Symbol(others, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 13, 7)) + + } = {}, + >( + attrs: Attrs & U, NewA>, +>attrs : Symbol(attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 15, 4)) +>Attrs : Symbol(Attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 1, 70)) +>ComponentProps : Symbol(ComponentProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 38)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) +>U : Symbol(U, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 10, 8)) +>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) + + ): StyledFunction; +>StyledFunction : Symbol(StyledFunction, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 40)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 5, 25)) +>O : Symbol(O, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 6, 31)) +>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) +>A : Symbol(A, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 7, 24)) +>NewA : Symbol(NewA, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 11, 6)) +} + +interface StyledInterface { +>StyledInterface : Symbol(StyledInterface, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 18, 1)) + + >(component: C): StyledFunction; +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 3)) +>ComponentType : Symbol(ComponentType, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 0, 0)) +>component : Symbol(component, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 33)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 3)) +>StyledFunction : Symbol(StyledFunction, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 3, 40)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 21, 3)) +} + +declare const styled: StyledInterface; +>styled : Symbol(styled, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 13)) +>StyledInterface : Symbol(StyledInterface, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 18, 1)) + +interface BaseProps { +>BaseProps : Symbol(BaseProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 38)) + + as?: "select" | "input"; +>as : Symbol(BaseProps.as, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 26, 21)) +} + +declare const Flex: (props: BaseProps) => null; +>Flex : Symbol(Flex, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 30, 13)) +>props : Symbol(props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 30, 21)) +>BaseProps : Symbol(BaseProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 38)) + +export const StyledSelect = styled(Flex).attrs({ +>StyledSelect : Symbol(StyledSelect, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 32, 12)) +>styled(Flex).attrs : Symbol(StyledFunction.attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 9, 3)) +>styled : Symbol(styled, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 24, 13)) +>Flex : Symbol(Flex, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 30, 13)) +>attrs : Symbol(StyledFunction.attrs, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 9, 3)) + + as: "select", +>as : Symbol(as, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts, 32, 48)) + +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.types b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.types new file mode 100644 index 0000000000000..ae23832fdd9c0 --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix1.types @@ -0,0 +1,89 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts === +type ComponentType

= (p: P) => any; +>ComponentType : ComponentType

+> : ^^^^^^^^^^^^^^^^ +>p : P +> : ^ + +type ComponentProps = C extends ComponentType ? P : never; +>ComponentProps : ComponentProps +> : ^^^^^^^^^^^^^^^^^ + +type Attrs> = A; +>Attrs : A +> : ^ + +interface StyledFunction< + C extends ComponentType, + O extends object = {}, + A extends keyof any = never, +> { + attrs< +>attrs : & U> & { [others: string]: any; } = {}>(attrs: Attrs & U, NewA>) => StyledFunction +> : ^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ + + U, + NewA extends Partial & U> & { + [others: string]: any; +>others : string +> : ^^^^^^ + + } = {}, + >( + attrs: Attrs & U, NewA>, +>attrs : NewA +> : ^^^^ + + ): StyledFunction; +} + +interface StyledInterface { + >(component: C): StyledFunction; +>component : C +> : ^ +} + +declare const styled: StyledInterface; +>styled : StyledInterface +> : ^^^^^^^^^^^^^^^ + +interface BaseProps { + as?: "select" | "input"; +>as : "select" | "input" | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +} + +declare const Flex: (props: BaseProps) => null; +>Flex : (props: BaseProps) => null +> : ^ ^^ ^^^^^ +>props : BaseProps +> : ^^^^^^^^^ + +export const StyledSelect = styled(Flex).attrs({ +>StyledSelect : StyledFunction<(props: BaseProps) => null, { as: "select"; }, "as"> +> : ^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>styled(Flex).attrs({ as: "select",}) : StyledFunction<(props: BaseProps) => null, { as: "select"; }, "as"> +> : ^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>styled(Flex).attrs : & { [others: string]: any; } = {}>(attrs: NewA) => StyledFunction<(props: BaseProps) => null, {} & NewA, keyof NewA> +> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>styled(Flex) : StyledFunction<(props: BaseProps) => null, {}, never> +> : ^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^ +>styled : StyledInterface +> : ^^^^^^^^^^^^^^^ +>Flex : (props: BaseProps) => null +> : ^ ^^ ^^^^^ +>attrs : & { [others: string]: any; } = {}>(attrs: NewA) => StyledFunction<(props: BaseProps) => null, {} & NewA, keyof NewA> +> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ +>{ as: "select",} : { as: "select"; } +> : ^^^^^^^^^^^^^^^^^ + + as: "select", +>as : "select" +> : ^^^^^^^^ +>"select" : "select" +> : ^^^^^^^^ + +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix2.symbols b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix2.symbols new file mode 100644 index 0000000000000..0776e0ce7aa2e --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix2.symbols @@ -0,0 +1,83 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts === +type IntrinsicElements = { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 0, 0)) + + a: { +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 0, 26)) + + href?: string; +>href : Symbol(href, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 1, 6)) + + }; + div: { +>div : Symbol(div, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 3, 4)) + + dir?: string; +>dir : Symbol(dir, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 4, 8)) + + }; +}; + +type Component = (props: Props) => unknown; +>Component : Symbol(Component, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 7, 2)) +>Props : Symbol(Props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 9, 15)) +>props : Symbol(props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 9, 25)) +>Props : Symbol(Props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 9, 15)) + +interface NestedMDXComponents { +>NestedMDXComponents : Symbol(NestedMDXComponents, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 9, 50)) + + [key: string]: Component; +>key : Symbol(key, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 12, 3)) +>Component : Symbol(Component, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 7, 2)) +} + +type MDXComponents = NestedMDXComponents & { +>MDXComponents : Symbol(MDXComponents, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 13, 1)) +>NestedMDXComponents : Symbol(NestedMDXComponents, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 9, 50)) + + [Key in keyof IntrinsicElements]?: Component; +>Key : Symbol(Key, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 16, 3)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 0, 0)) +>Component : Symbol(Component, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 7, 2)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 0, 0)) +>Key : Symbol(Key, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 16, 3)) + +}; + +export interface MDXProps { +>MDXProps : Symbol(MDXProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 17, 2)) + + components?: MDXComponents; +>components : Symbol(MDXProps.components, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 19, 27)) +>MDXComponents : Symbol(MDXComponents, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 13, 1)) +} + +declare function MyMDXComponent(props: MDXProps): null; +>MyMDXComponent : Symbol(MyMDXComponent, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 21, 1)) +>props : Symbol(props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 23, 32)) +>MDXProps : Symbol(MDXProps, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 17, 2)) + +MyMDXComponent({ +>MyMDXComponent : Symbol(MyMDXComponent, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 21, 1)) + + components: { +>components : Symbol(components, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 25, 16)) + + a(props) { +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 26, 15)) +>props : Symbol(props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 27, 6)) + + return null; + }, + div(props) { +>div : Symbol(div, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 29, 6)) +>props : Symbol(props, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts, 30, 8)) + + return null; + }, + }, +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix2.types b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix2.types new file mode 100644 index 0000000000000..d29a47924fbe0 --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix2.types @@ -0,0 +1,91 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts === +type IntrinsicElements = { +>IntrinsicElements : IntrinsicElements +> : ^^^^^^^^^^^^^^^^^ + + a: { +>a : { href?: string; } +> : ^^^^^^^^^ ^^^ + + href?: string; +>href : string | undefined +> : ^^^^^^^^^^^^^^^^^^ + + }; + div: { +>div : { dir?: string; } +> : ^^^^^^^^ ^^^ + + dir?: string; +>dir : string | undefined +> : ^^^^^^^^^^^^^^^^^^ + + }; +}; + +type Component = (props: Props) => unknown; +>Component : Component +> : ^^^^^^^^^^^^^^^^ +>props : Props +> : ^^^^^ + +interface NestedMDXComponents { + [key: string]: Component; +>key : string +> : ^^^^^^ +} + +type MDXComponents = NestedMDXComponents & { +>MDXComponents : MDXComponents +> : ^^^^^^^^^^^^^ + + [Key in keyof IntrinsicElements]?: Component; +}; + +export interface MDXProps { + components?: MDXComponents; +>components : MDXComponents | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +} + +declare function MyMDXComponent(props: MDXProps): null; +>MyMDXComponent : (props: MDXProps) => null +> : ^ ^^ ^^^^^ +>props : MDXProps +> : ^^^^^^^^ + +MyMDXComponent({ +>MyMDXComponent({ components: { a(props) { return null; }, div(props) { return null; }, },}) : null +> : ^^^^ +>MyMDXComponent : (props: MDXProps) => null +> : ^ ^^ ^^^^^ +>{ components: { a(props) { return null; }, div(props) { return null; }, },} : { components: { a(props: { href?: string; }): null; div(props: { dir?: string; }): null; }; } +> : ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + + components: { +>components : { a(props: { href?: string; }): null; div(props: { dir?: string; }): null; } +> : ^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^ +>{ a(props) { return null; }, div(props) { return null; }, } : { a(props: { href?: string; }): null; div(props: { dir?: string; }): null; } +> : ^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^ + + a(props) { +>a : (props: { href?: string; }) => null +> : ^ ^^^^^^^^^^^ ^^^^^^^^^^^^ +>props : { href?: string; } +> : ^^^^^^^^^ ^^^ + + return null; + }, + div(props) { +>div : (props: { dir?: string; }) => null +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^ +>props : { dir?: string; } +> : ^^^^^^^^ ^^^ + + return null; + }, + }, +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix3.symbols b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix3.symbols new file mode 100644 index 0000000000000..39658147169d7 --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix3.symbols @@ -0,0 +1,85 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts === +type TypeMap = { +>TypeMap : Symbol(TypeMap, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 0, 0)) + + str: "a" | "b" | "c"; +>str : Symbol(str, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 0, 16)) + + num: 1 | 2 | 3; +>num : Symbol(num, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 1, 23)) + +}; + +declare function test1< +>test1 : Symbol(test1, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 3, 2)) + + T extends { [K in keyof TypeMap]: TypeMap[K][] } & { [k: string]: any[] }, +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 5, 23)) +>K : Symbol(K, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 6, 15)) +>TypeMap : Symbol(TypeMap, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 0, 0)) +>TypeMap : Symbol(TypeMap, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 0, 0)) +>K : Symbol(K, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 6, 15)) +>k : Symbol(k, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 6, 56)) + +>(arg: T): T; +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 7, 2)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 5, 23)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 5, 23)) + +const result = test1({ +>result : Symbol(result, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 9, 5)) +>test1 : Symbol(test1, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 3, 2)) + + num: [1, 2], +>num : Symbol(num, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 9, 22)) + + str: ["a", "b"], +>str : Symbol(str, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 10, 14)) + + bool: [true, false], +>bool : Symbol(bool, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 11, 18)) + +}); + +declare function test2(a: { type: "foo" | "bar" } & { type: any }): void; +>test2 : Symbol(test2, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 13, 3)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 15, 23)) +>type : Symbol(type, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 15, 27)) +>type : Symbol(type, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 15, 53)) + +test2({ type: "foo" }); +>test2 : Symbol(test2, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 13, 3)) +>type : Symbol(type, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 17, 7)) + +// https://github.com/microsoft/TypeScript/issues/59473 + +const x: { ml: any } & { ml: 'edge' } = { ml: 'edge' }; +>x : Symbol(x, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 21, 5)) +>ml : Symbol(ml, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 21, 10)) +>ml : Symbol(ml, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 21, 24)) +>ml : Symbol(ml, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 21, 41)) + +const a: [any] & [1] = [1]; +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 22, 5)) + +const b: any[] & 1[] = [1, 1]; +>b : Symbol(b, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 23, 5)) + +const c: { a: any } & { a: 1 } = { a: 1 }; +>c : Symbol(c, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 24, 5)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 24, 10)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 24, 23)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 24, 34)) + +const d: (() => { a: 1 }) & (() => { a: any }) = () => ({ +>d : Symbol(d, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 25, 5)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 25, 17)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 25, 36)) + + a: 1, +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts, 25, 57)) + +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix3.types b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix3.types new file mode 100644 index 0000000000000..c5ac24db84967 --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix3.types @@ -0,0 +1,159 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts === +type TypeMap = { +>TypeMap : TypeMap +> : ^^^^^^^ + + str: "a" | "b" | "c"; +>str : "a" | "b" | "c" +> : ^^^^^^^^^^^^^^^ + + num: 1 | 2 | 3; +>num : 1 | 2 | 3 +> : ^^^^^^^^^ + +}; + +declare function test1< +>test1 : (arg: T) => T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ + + T extends { [K in keyof TypeMap]: TypeMap[K][] } & { [k: string]: any[] }, +>k : string +> : ^^^^^^ + +>(arg: T): T; +>arg : T +> : ^ + +const result = test1({ +>result : { num: (1 | 2)[]; str: ("a" | "b")[]; bool: boolean[]; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>test1({ num: [1, 2], str: ["a", "b"], bool: [true, false],}) : { num: (1 | 2)[]; str: ("a" | "b")[]; bool: boolean[]; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>test1 : (arg: T) => T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ num: [1, 2], str: ["a", "b"], bool: [true, false],} : { num: (1 | 2)[]; str: ("a" | "b")[]; bool: boolean[]; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + num: [1, 2], +>num : (1 | 2)[] +> : ^^^^^^^^^ +>[1, 2] : (1 | 2)[] +> : ^^^^^^^^^ +>1 : 1 +> : ^ +>2 : 2 +> : ^ + + str: ["a", "b"], +>str : ("a" | "b")[] +> : ^^^^^^^^^^^^^ +>["a", "b"] : ("a" | "b")[] +> : ^^^^^^^^^^^^^ +>"a" : "a" +> : ^^^ +>"b" : "b" +> : ^^^ + + bool: [true, false], +>bool : boolean[] +> : ^^^^^^^^^ +>[true, false] : boolean[] +> : ^^^^^^^^^ +>true : true +> : ^^^^ +>false : false +> : ^^^^^ + +}); + +declare function test2(a: { type: "foo" | "bar" } & { type: any }): void; +>test2 : (a: { type: "foo" | "bar"; } & { type: any; }) => void +> : ^ ^^ ^^^^^ +>a : { type: "foo" | "bar"; } & { type: any; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>type : "foo" | "bar" +> : ^^^^^^^^^^^^^ +>type : any + +test2({ type: "foo" }); +>test2({ type: "foo" }) : void +> : ^^^^ +>test2 : (a: { type: "foo" | "bar"; } & { type: any; }) => void +> : ^ ^^ ^^^^^ +>{ type: "foo" } : { type: "foo"; } +> : ^^^^^^^^^^^^^^^^ +>type : "foo" +> : ^^^^^ +>"foo" : "foo" +> : ^^^^^ + +// https://github.com/microsoft/TypeScript/issues/59473 + +const x: { ml: any } & { ml: 'edge' } = { ml: 'edge' }; +>x : { ml: any; } & { ml: "edge"; } +> : ^^^^^^ ^^^^^^^^^^^^ ^^^ +>ml : any +>ml : "edge" +> : ^^^^^^ +>{ ml: 'edge' } : { ml: "edge"; } +> : ^^^^^^^^^^^^^^^ +>ml : "edge" +> : ^^^^^^ +>'edge' : "edge" +> : ^^^^^^ + +const a: [any] & [1] = [1]; +>a : [any] & [1] +> : ^^^^^^^^^^^ +>[1] : [1] +> : ^^^ +>1 : 1 +> : ^ + +const b: any[] & 1[] = [1, 1]; +>b : any[] & 1[] +> : ^^^^^^^^^^^ +>[1, 1] : 1[] +> : ^^^ +>1 : 1 +> : ^ +>1 : 1 +> : ^ + +const c: { a: any } & { a: 1 } = { a: 1 }; +>c : { a: any; } & { a: 1; } +> : ^^^^^ ^^^^^^^^^^^ ^^^ +>a : any +>a : 1 +> : ^ +>{ a: 1 } : { a: 1; } +> : ^^^^^^^^^ +>a : 1 +> : ^ +>1 : 1 +> : ^ + +const d: (() => { a: 1 }) & (() => { a: any }) = () => ({ +>d : (() => { a: 1; }) & (() => { a: any; }) +> : ^^^^^^^ ^^^^^^^^^^^ ^ +>a : 1 +> : ^ +>a : any +>() => ({ a: 1,}) : () => { a: 1; } +> : ^^^^^^^^^^^^^^^ +>({ a: 1,}) : { a: 1; } +> : ^^^^^^^^^ +>{ a: 1,} : { a: 1; } +> : ^^^^^^^^^ + + a: 1, +>a : 1 +> : ^ +>1 : 1 +> : ^ + +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.errors.txt b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.errors.txt new file mode 100644 index 0000000000000..70a344908035e --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.errors.txt @@ -0,0 +1,61 @@ +contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts(33,12): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts(48,15): error TS2322: Type '"bar"' is not assignable to type '"foo"'. + + +==== contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts (2 errors) ==== + declare function test1( + arg: { a: (arg: number) => void } & { [k: string]: (arg: any) => void }, + ): unknown; + + test1({ + a: (arg) => {}, + b: (arg) => {}, + }); + + declare function test2( + arg: { a: (arg: { foo: string }) => void } & { + [k: string]: (arg: { foo: any }) => void; + }, + ): unknown; + + test2({ + a: (arg) => {}, + b: (arg) => {}, + }); + + declare function test3( + arg: { a: () => "foo" } & { + [k: string]: () => any; + }, + ): unknown; + + test3({ + a: () => "foo", + b: () => "bar", + }); + + test3({ + a: () => "bar", + ~~~~~ +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! related TS6502 contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts:22:13: The expected type comes from the return type of this signature. + }); + + declare function test4( + arg: { a: () => { prop: "foo" } } & { + [k: string]: () => { prop: any }; + }, + ): unknown; + + test4({ + a: () => ({ prop: "foo" }), + b: () => ({ prop: "bar" }), + }); + + test4({ + a: () => ({ prop: "bar" }), + ~~~~ +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! related TS6500 contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts:37:21: The expected type comes from property 'prop' which is declared here on type '{ prop: "foo"; }' + }); + \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.symbols b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.symbols new file mode 100644 index 0000000000000..0114a153b5047 --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.symbols @@ -0,0 +1,127 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts === +declare function test1( +>test1 : Symbol(test1, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 0, 0)) + + arg: { a: (arg: number) => void } & { [k: string]: (arg: any) => void }, +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 0, 23)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 1, 8)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 1, 13)) +>k : Symbol(k, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 1, 41)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 1, 54)) + +): unknown; + +test1({ +>test1 : Symbol(test1, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 0, 0)) + + a: (arg) => {}, +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 4, 7)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 5, 6)) + + b: (arg) => {}, +>b : Symbol(b, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 5, 17)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 6, 6)) + +}); + +declare function test2( +>test2 : Symbol(test2, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 7, 3)) + + arg: { a: (arg: { foo: string }) => void } & { +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 9, 23)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 10, 8)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 10, 13)) +>foo : Symbol(foo, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 10, 19)) + + [k: string]: (arg: { foo: any }) => void; +>k : Symbol(k, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 11, 5)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 11, 18)) +>foo : Symbol(foo, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 11, 24)) + + }, +): unknown; + +test2({ +>test2 : Symbol(test2, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 7, 3)) + + a: (arg) => {}, +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 15, 7)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 16, 6)) + + b: (arg) => {}, +>b : Symbol(b, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 16, 17)) +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 17, 6)) + +}); + +declare function test3( +>test3 : Symbol(test3, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 18, 3)) + + arg: { a: () => "foo" } & { +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 20, 23)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 21, 8)) + + [k: string]: () => any; +>k : Symbol(k, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 22, 5)) + + }, +): unknown; + +test3({ +>test3 : Symbol(test3, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 18, 3)) + + a: () => "foo", +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 26, 7)) + + b: () => "bar", +>b : Symbol(b, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 27, 17)) + +}); + +test3({ +>test3 : Symbol(test3, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 18, 3)) + + a: () => "bar", +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 31, 7)) + +}); + +declare function test4( +>test4 : Symbol(test4, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 33, 3)) + + arg: { a: () => { prop: "foo" } } & { +>arg : Symbol(arg, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 35, 23)) +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 36, 8)) +>prop : Symbol(prop, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 36, 19)) + + [k: string]: () => { prop: any }; +>k : Symbol(k, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 37, 5)) +>prop : Symbol(prop, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 37, 24)) + + }, +): unknown; + +test4({ +>test4 : Symbol(test4, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 33, 3)) + + a: () => ({ prop: "foo" }), +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 41, 7)) +>prop : Symbol(prop, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 42, 13)) + + b: () => ({ prop: "bar" }), +>b : Symbol(b, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 42, 29)) +>prop : Symbol(prop, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 43, 13)) + +}); + +test4({ +>test4 : Symbol(test4, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 33, 3)) + + a: () => ({ prop: "bar" }), +>a : Symbol(a, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 46, 7)) +>prop : Symbol(prop, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts, 47, 13)) + +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.types b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.types new file mode 100644 index 0000000000000..8900e319846d9 --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix4.types @@ -0,0 +1,242 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts === +declare function test1( +>test1 : (arg: { a: (arg: number) => void; } & { [k: string]: (arg: any) => void; }) => unknown +> : ^ ^^ ^^^^^ + + arg: { a: (arg: number) => void } & { [k: string]: (arg: any) => void }, +>arg : { a: (arg: number) => void; } & { [k: string]: (arg: any) => void; } +> : ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^ +>a : (arg: number) => void +> : ^ ^^ ^^^^^ +>arg : number +> : ^^^^^^ +>k : string +> : ^^^^^^ +>arg : any +> : ^^^ + +): unknown; + +test1({ +>test1({ a: (arg) => {}, b: (arg) => {},}) : unknown +> : ^^^^^^^ +>test1 : (arg: { a: (arg: number) => void; } & { [k: string]: (arg: any) => void; }) => unknown +> : ^ ^^ ^^^^^ +>{ a: (arg) => {}, b: (arg) => {},} : { a: (arg: number) => void; b: (arg: any) => void; } +> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ + + a: (arg) => {}, +>a : (arg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg) => {} : (arg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg : number +> : ^^^^^^ + + b: (arg) => {}, +>b : (arg: any) => void +> : ^ ^^^^^^^^^^^^^^ +>(arg) => {} : (arg: any) => void +> : ^ ^^^^^^^^^^^^^^ +>arg : any +> : ^^^ + +}); + +declare function test2( +>test2 : (arg: { a: (arg: { foo: string; }) => void; } & { [k: string]: (arg: { foo: any; }) => void; }) => unknown +> : ^ ^^ ^^^^^ + + arg: { a: (arg: { foo: string }) => void } & { +>arg : { a: (arg: { foo: string; }) => void; } & { [k: string]: (arg: { foo: any; }) => void; } +> : ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^ +>a : (arg: { foo: string; }) => void +> : ^ ^^ ^^^^^ +>arg : { foo: string; } +> : ^^^^^^^ ^^^ +>foo : string +> : ^^^^^^ + + [k: string]: (arg: { foo: any }) => void; +>k : string +> : ^^^^^^ +>arg : { foo: any; } +> : ^^^^^^^ ^^^ +>foo : any +> : ^^^ + + }, +): unknown; + +test2({ +>test2({ a: (arg) => {}, b: (arg) => {},}) : unknown +> : ^^^^^^^ +>test2 : (arg: { a: (arg: { foo: string; }) => void; } & { [k: string]: (arg: { foo: any; }) => void; }) => unknown +> : ^ ^^ ^^^^^ +>{ a: (arg) => {}, b: (arg) => {},} : { a: (arg: { foo: string; }) => void; b: (arg: { foo: any; }) => void; } +> : ^^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^ + + a: (arg) => {}, +>a : (arg: { foo: string; }) => void +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^ +>(arg) => {} : (arg: { foo: string; }) => void +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^ +>arg : { foo: string; } +> : ^^^^^^^ ^^^ + + b: (arg) => {}, +>b : (arg: { foo: any; }) => void +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^ +>(arg) => {} : (arg: { foo: any; }) => void +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^ +>arg : { foo: any; } +> : ^^^^^^^ ^^^ + +}); + +declare function test3( +>test3 : (arg: { a: () => "foo"; } & { [k: string]: () => any; }) => unknown +> : ^ ^^ ^^^^^ + + arg: { a: () => "foo" } & { +>arg : { a: () => "foo"; } & { [k: string]: () => any; } +> : ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>a : () => "foo" +> : ^^^^^^ + + [k: string]: () => any; +>k : string +> : ^^^^^^ + + }, +): unknown; + +test3({ +>test3({ a: () => "foo", b: () => "bar",}) : unknown +> : ^^^^^^^ +>test3 : (arg: { a: () => "foo"; } & { [k: string]: () => any; }) => unknown +> : ^ ^^ ^^^^^ +>{ a: () => "foo", b: () => "bar",} : { a: () => "foo"; b: () => string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + a: () => "foo", +>a : () => "foo" +> : ^^^^^^^^^^^ +>() => "foo" : () => "foo" +> : ^^^^^^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + b: () => "bar", +>b : () => string +> : ^^^^^^^^^^^^ +>() => "bar" : () => string +> : ^^^^^^^^^^^^ +>"bar" : "bar" +> : ^^^^^ + +}); + +test3({ +>test3({ a: () => "bar",}) : unknown +> : ^^^^^^^ +>test3 : (arg: { a: () => "foo"; } & { [k: string]: () => any; }) => unknown +> : ^ ^^ ^^^^^ +>{ a: () => "bar",} : { a: () => "bar"; } +> : ^^^^^^^^^^^^^^^^^^^ + + a: () => "bar", +>a : () => "bar" +> : ^^^^^^^^^^^ +>() => "bar" : () => "bar" +> : ^^^^^^^^^^^ +>"bar" : "bar" +> : ^^^^^ + +}); + +declare function test4( +>test4 : (arg: { a: () => { prop: "foo"; }; } & { [k: string]: () => { prop: any; }; }) => unknown +> : ^ ^^ ^^^^^ + + arg: { a: () => { prop: "foo" } } & { +>arg : { a: () => { prop: "foo"; }; } & { [k: string]: () => { prop: any; }; } +> : ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>a : () => { prop: "foo"; } +> : ^^^^^^ +>prop : "foo" +> : ^^^^^ + + [k: string]: () => { prop: any }; +>k : string +> : ^^^^^^ +>prop : any +> : ^^^ + + }, +): unknown; + +test4({ +>test4({ a: () => ({ prop: "foo" }), b: () => ({ prop: "bar" }),}) : unknown +> : ^^^^^^^ +>test4 : (arg: { a: () => { prop: "foo"; }; } & { [k: string]: () => { prop: any; }; }) => unknown +> : ^ ^^ ^^^^^ +>{ a: () => ({ prop: "foo" }), b: () => ({ prop: "bar" }),} : { a: () => { prop: "foo"; }; b: () => { prop: string; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + a: () => ({ prop: "foo" }), +>a : () => { prop: "foo"; } +> : ^^^^^^^^^^^^^^^^^^^^^^ +>() => ({ prop: "foo" }) : () => { prop: "foo"; } +> : ^^^^^^^^^^^^^^^^^^^^^^ +>({ prop: "foo" }) : { prop: "foo"; } +> : ^^^^^^^^^^^^^^^^ +>{ prop: "foo" } : { prop: "foo"; } +> : ^^^^^^^^^^^^^^^^ +>prop : "foo" +> : ^^^^^ +>"foo" : "foo" +> : ^^^^^ + + b: () => ({ prop: "bar" }), +>b : () => { prop: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>() => ({ prop: "bar" }) : () => { prop: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>({ prop: "bar" }) : { prop: string; } +> : ^^^^^^^^^^^^^^^^^ +>{ prop: "bar" } : { prop: string; } +> : ^^^^^^^^^^^^^^^^^ +>prop : string +> : ^^^^^^ +>"bar" : "bar" +> : ^^^^^ + +}); + +test4({ +>test4({ a: () => ({ prop: "bar" }),}) : unknown +> : ^^^^^^^ +>test4 : (arg: { a: () => { prop: "foo"; }; } & { [k: string]: () => { prop: any; }; }) => unknown +> : ^ ^^ ^^^^^ +>{ a: () => ({ prop: "bar" }),} : { a: () => { prop: "bar"; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + a: () => ({ prop: "bar" }), +>a : () => { prop: "bar"; } +> : ^^^^^^^^^^^^^^^^^^^^^^ +>() => ({ prop: "bar" }) : () => { prop: "bar"; } +> : ^^^^^^^^^^^^^^^^^^^^^^ +>({ prop: "bar" }) : { prop: "bar"; } +> : ^^^^^^^^^^^^^^^^ +>{ prop: "bar" } : { prop: "bar"; } +> : ^^^^^^^^^^^^^^^^ +>prop : "bar" +> : ^^^^^ +>"bar" : "bar" +> : ^^^^^ + +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix5.symbols b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix5.symbols new file mode 100644 index 0000000000000..aa654c54653c8 --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix5.symbols @@ -0,0 +1,167 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts === +type ComputedGetter = (oldValue?: T) => T; +>ComputedGetter : Symbol(ComputedGetter, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 0)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 20)) +>oldValue : Symbol(oldValue, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 26)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 20)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 20)) + +type ComputedOptions = Record>; +>ComputedOptions : Symbol(ComputedOptions, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 45)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>ComputedGetter : Symbol(ComputedGetter, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 0)) + +type ExtractComputedReturns = { +>ExtractComputedReturns : Symbol(ExtractComputedReturns, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 1, 59)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 3, 28)) + + [key in keyof T]: T[key] extends (...args: any[]) => infer TReturn +>key : Symbol(key, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 4, 3)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 3, 28)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 3, 28)) +>key : Symbol(key, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 4, 3)) +>args : Symbol(args, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 4, 36)) +>TReturn : Symbol(TReturn, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 4, 60)) + + ? TReturn +>TReturn : Symbol(TReturn, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 4, 60)) + + : never; +}; + +interface ComponentOptionsBase { +>ComponentOptionsBase : Symbol(ComponentOptionsBase, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 7, 2)) +>D : Symbol(D, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 9, 31)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 9, 33)) +>ComputedOptions : Symbol(ComputedOptions, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 45)) + + data?: D; +>data : Symbol(ComponentOptionsBase.data, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 9, 62)) +>D : Symbol(D, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 9, 31)) + + computed?: C; +>computed : Symbol(ComponentOptionsBase.computed, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 10, 11)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 9, 33)) +} + +type ComponentPublicInstance = D & +>ComponentPublicInstance : Symbol(ComponentPublicInstance, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 12, 1)) +>D : Symbol(D, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 14, 29)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 14, 36)) +>ComputedOptions : Symbol(ComputedOptions, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 45)) +>D : Symbol(D, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 14, 29)) + + ExtractComputedReturns; +>ExtractComputedReturns : Symbol(ExtractComputedReturns, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 1, 59)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 14, 36)) + +type ComponentOptions< +>ComponentOptions : Symbol(ComponentOptions, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 15, 28)) + + D = any, +>D : Symbol(D, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 17, 22)) + + C extends ComputedOptions = any, +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 18, 10)) +>ComputedOptions : Symbol(ComputedOptions, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 0, 45)) + +> = ComponentOptionsBase & ThisType>; +>ComponentOptionsBase : Symbol(ComponentOptionsBase, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 7, 2)) +>D : Symbol(D, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 17, 22)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 18, 10)) +>ThisType : Symbol(ThisType, Decl(lib.es5.d.ts, --, --)) +>ComponentPublicInstance : Symbol(ComponentPublicInstance, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 12, 1)) +>D : Symbol(D, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 17, 22)) +>C : Symbol(C, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 18, 10)) + +interface App { +>App : Symbol(App, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 20, 73)) + + mixin(mixin: ComponentOptions): this; +>mixin : Symbol(App.mixin, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 22, 15)) +>mixin : Symbol(mixin, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 23, 8)) +>ComponentOptions : Symbol(ComponentOptions, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 15, 28)) +} + +interface InjectionKey extends Symbol {} +>InjectionKey : Symbol(InjectionKey, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 24, 1)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 26, 23)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --)) + +interface Ref { +>Ref : Symbol(Ref, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 26, 43)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 28, 14)) + + _v: T; +>_v : Symbol(Ref._v, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 28, 18)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 28, 14)) +} + +declare function reactive(target: T): Ref; +>reactive : Symbol(reactive, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 30, 1)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 32, 26)) +>target : Symbol(target, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 32, 44)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 32, 26)) +>Ref : Symbol(Ref, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 26, 43)) +>T : Symbol(T, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 32, 26)) + +interface ThemeInstance { +>ThemeInstance : Symbol(ThemeInstance, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 32, 63)) + + readonly name: Readonly>; +>name : Symbol(ThemeInstance.name, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 34, 25)) +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>Ref : Symbol(Ref, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 26, 43)) +} + +declare const ThemeSymbol: InjectionKey; +>ThemeSymbol : Symbol(ThemeSymbol, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 38, 13)) +>InjectionKey : Symbol(InjectionKey, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 24, 1)) +>ThemeInstance : Symbol(ThemeInstance, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 32, 63)) + +declare function inject( +>inject : Symbol(inject, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 38, 55)) + + this: ComponentPublicInstance, +>this : Symbol(this, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 40, 24)) +>ComponentPublicInstance : Symbol(ComponentPublicInstance, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 12, 1)) + + key: InjectionKey | string, +>key : Symbol(key, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 41, 32)) +>InjectionKey : Symbol(InjectionKey, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 24, 1)) + +): any; + +declare const app: App; +>app : Symbol(app, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 45, 13)) +>App : Symbol(App, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 20, 73)) + +app.mixin({ +>app.mixin : Symbol(App.mixin, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 22, 15)) +>app : Symbol(app, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 45, 13)) +>mixin : Symbol(App.mixin, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 22, 15)) + + computed: { +>computed : Symbol(computed, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 46, 11)) + + $vuetify() { +>$vuetify : Symbol($vuetify, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 47, 13)) + + // this is meant to be `any` here + return reactive({ +>reactive : Symbol(reactive, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 30, 1)) + + theme: inject.call(this, ThemeSymbol), +>theme : Symbol(theme, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 50, 23)) +>inject.call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --)) +>inject : Symbol(inject, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 38, 55)) +>call : Symbol(CallableFunction.call, Decl(lib.es5.d.ts, --, --)) +>ThemeSymbol : Symbol(ThemeSymbol, Decl(contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts, 38, 13)) + + }); + }, + }, +}); + diff --git a/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix5.types b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix5.types new file mode 100644 index 0000000000000..6ba5347f0336f --- /dev/null +++ b/tests/baselines/reference/contextualTypeBasedOnIntersectionWithAnyInTheMix5.types @@ -0,0 +1,148 @@ +//// [tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts] //// + +=== contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts === +type ComputedGetter = (oldValue?: T) => T; +>ComputedGetter : ComputedGetter +> : ^^^^^^^^^^^^^^^^^ +>oldValue : T | undefined +> : ^^^^^^^^^^^^^ + +type ComputedOptions = Record>; +>ComputedOptions : ComputedOptions +> : ^^^^^^^^^^^^^^^ + +type ExtractComputedReturns = { +>ExtractComputedReturns : ExtractComputedReturns +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ + + [key in keyof T]: T[key] extends (...args: any[]) => infer TReturn +>args : any[] +> : ^^^^^ + + ? TReturn + : never; +}; + +interface ComponentOptionsBase { + data?: D; +>data : D | undefined +> : ^^^^^^^^^^^^^ + + computed?: C; +>computed : C | undefined +> : ^^^^^^^^^^^^^ +} + +type ComponentPublicInstance = D & +>ComponentPublicInstance : ComponentPublicInstance +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + ExtractComputedReturns; + +type ComponentOptions< +>ComponentOptions : ComponentOptions +> : ^^^^^^^^^^^^^^^^^^^^^^ + + D = any, + C extends ComputedOptions = any, +> = ComponentOptionsBase & ThisType>; + +interface App { + mixin(mixin: ComponentOptions): this; +>mixin : (mixin: ComponentOptions) => this +> : ^ ^^ ^^^^^ +>mixin : ComponentOptions +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ +} + +interface InjectionKey extends Symbol {} + +interface Ref { + _v: T; +>_v : T +> : ^ +} + +declare function reactive(target: T): Ref; +>reactive : (target: T) => Ref +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>target : T +> : ^ + +interface ThemeInstance { + readonly name: Readonly>; +>name : Readonly> +> : ^^^^^^^^^^^^^^^^^^^^^ +} + +declare const ThemeSymbol: InjectionKey; +>ThemeSymbol : InjectionKey +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +declare function inject( +>inject : (this: ComponentPublicInstance, key: InjectionKey | string) => any +> : ^ ^^ ^^ ^^ ^^^^^ + + this: ComponentPublicInstance, +>this : ExtractComputedReturns<{}> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ + + key: InjectionKey | string, +>key : string | InjectionKey +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +): any; + +declare const app: App; +>app : App +> : ^^^ + +app.mixin({ +>app.mixin({ computed: { $vuetify() { // this is meant to be `any` here return reactive({ theme: inject.call(this, ThemeSymbol), }); }, },}) : App +> : ^^^ +>app.mixin : (mixin: ComponentOptions) => App +> : ^ ^^ ^^^^^^^^ +>app : App +> : ^^^ +>mixin : (mixin: ComponentOptions) => App +> : ^ ^^ ^^^^^^^^ +>{ computed: { $vuetify() { // this is meant to be `any` here return reactive({ theme: inject.call(this, ThemeSymbol), }); }, },} : { computed: { $vuetify(): Ref<{ theme: any; }>; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + computed: { +>computed : { $vuetify(): Ref<{ theme: any; }>; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ $vuetify() { // this is meant to be `any` here return reactive({ theme: inject.call(this, ThemeSymbol), }); }, } : { $vuetify(): Ref<{ theme: any; }>; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + $vuetify() { +>$vuetify : () => Ref<{ theme: any; }> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ + + // this is meant to be `any` here + return reactive({ +>reactive({ theme: inject.call(this, ThemeSymbol), }) : Ref<{ theme: any; }> +> : ^^^^^^^^^^^^^^^^^^^^ +>reactive : (target: T) => Ref +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ theme: inject.call(this, ThemeSymbol), } : { theme: any; } +> : ^^^^^^^^^^^^^^^ + + theme: inject.call(this, ThemeSymbol), +>theme : any +>inject.call(this, ThemeSymbol) : any +>inject.call : (this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^^^^ ^^ ^^^^^ +>inject : (this: ComponentPublicInstance, key: InjectionKey | string) => any +> : ^ ^^ ^^ ^^ ^^^^^ +>call : (this: (this: T, ...args: A) => R, thisArg: T, ...args: A) => R +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^^^^ ^^ ^^^^^ +>this : any +>ThemeSymbol : InjectionKey +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + }); + }, + }, +}); + diff --git a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.errors.txt b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.errors.txt new file mode 100644 index 0000000000000..c6927b2005ad0 --- /dev/null +++ b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.errors.txt @@ -0,0 +1,155 @@ +contextualTypeFunctionObjectPropertyIntersection.ts(84,5): error TS2353: Object literal may only specify known properties, and 'bar' does not exist in type '{ FOO?: Action<{ type: "FOO"; }> | undefined; } & { "*"?: Action<{ type: "FOO"; } | { type: "bar"; }> | undefined; }'. +contextualTypeFunctionObjectPropertyIntersection.ts(84,11): error TS7006: Parameter 'ev' implicitly has an 'any' type. + + +==== contextualTypeFunctionObjectPropertyIntersection.ts (2 errors) ==== + // repro from #48812 + + type Action = (ev: TEvent) => void; + + interface MachineConfig { + schema: { + events: TEvent; + }; + on?: { + [K in TEvent["type"]]?: Action; + } & { + "*"?: Action; + }; + } + + declare function createMachine( + config: MachineConfig + ): void; + + createMachine({ + schema: { + events: {} as { type: "FOO" } | { type: "BAR" }, + }, + on: { + FOO: (ev) => { + ev.type; // should be 'FOO' + }, + }, + }); + + createMachine({ + schema: { + events: {} as { type: "FOO" } | { type: "BAR" }, + }, + on: { + "*": (ev) => { + ev.type; // should be 'FOO' | 'BAR' + }, + }, + }); + + interface MachineConfig2 { + schema: { + events: TEvent; + }; + on?: { + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; + } & { + "*"?: Action; + }; + } + + declare function createMachine2( + config: MachineConfig2 + ): void; + + createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + FOO: (ev) => { + ev.type; // should be 'FOO' + }, + }, + }); + + createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + "*": (ev) => { + ev.type; // should be 'FOO' | 'bar' + }, + }, + }); + + createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + bar: (ev) => { + ~~~ +!!! error TS2353: Object literal may only specify known properties, and 'bar' does not exist in type '{ FOO?: Action<{ type: "FOO"; }> | undefined; } & { "*"?: Action<{ type: "FOO"; } | { type: "bar"; }> | undefined; }'. +!!! related TS6500 contextualTypeFunctionObjectPropertyIntersection.ts:46:3: The expected type comes from property 'on' which is declared here on type 'MachineConfig2<{ type: "FOO"; } | { type: "bar"; }>' + ~~ +!!! error TS7006: Parameter 'ev' implicitly has an 'any' type. + ev // any + }, + }, + }); + + // repro from #49307#issuecomment-1143103607 + + declare function createSlice( + reducers: { [K: string]: (state: string) => void } & { + [K in keyof T]: object; + } + ): void; + + createSlice({ + f(a) {}, + }); + + // repro from #49307#issuecomment-1196014488 + + type Validate = T & { [K in keyof T]: object } + declare function f any>>(s: S, x: Validate): void; + + f(0, { + foo: s => s + 1, + }) + + // repro from 49307#issuecomment-1195858950 + + type SliceCaseReducers = Record State | void>; + + type ValidateSliceCaseReducers> = ACR & { + [T in keyof ACR]: ACR[T] extends { + reducer(s: S, action?: infer A): any; + } + ? { + prepare(...a: never[]): Omit; + } + : {}; + }; + + declare function createSlice< + State, + CaseReducers extends SliceCaseReducers + >(options: { + initialState: State | (() => State); + reducers: ValidateSliceCaseReducers; + }): void; + + export const clientSlice = createSlice({ + initialState: { + username: "", + isLoggedIn: false, + userId: "", + avatar: "", + }, + reducers: { + onClientUserChanged(state) {}, + }, + }); + + \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols new file mode 100644 index 0000000000000..1a681fad41bf7 --- /dev/null +++ b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols @@ -0,0 +1,402 @@ +//// [tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts] //// + +=== contextualTypeFunctionObjectPropertyIntersection.ts === +// repro from #48812 + +type Action = (ev: TEvent) => void; +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 12)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 28)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 48)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 12)) + +interface MachineConfig { +>MachineConfig : Symbol(MachineConfig, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 68)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 24)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 40)) + + schema: { +>schema : Symbol(MachineConfig.schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 58)) + + events: TEvent; +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 5, 11)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 24)) + + }; + on?: { +>on : Symbol(MachineConfig.on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 7, 4)) + + [K in TEvent["type"]]?: Action; +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 9, 5)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 24)) +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 24)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 9, 51)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 9, 5)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 24)) + + } & { + "*"?: Action; +>"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 10, 7)) +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 4, 24)) + + }; +} + +declare function createMachine( +>createMachine : Symbol(createMachine, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 13, 1)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 15, 31)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 15, 47)) + + config: MachineConfig +>config : Symbol(config, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 15, 64)) +>MachineConfig : Symbol(MachineConfig, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 68)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 15, 31)) + +): void; + +createMachine({ +>createMachine : Symbol(createMachine, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 13, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 19, 15)) + + events: {} as { type: "FOO" } | { type: "BAR" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 20, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 21, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 21, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 22, 4)) + + FOO: (ev) => { +>FOO : Symbol(FOO, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 23, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 24, 10)) + + ev.type; // should be 'FOO' +>ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 21, 19)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 24, 10)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 21, 19)) + + }, + }, +}); + +createMachine({ +>createMachine : Symbol(createMachine, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 13, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 30, 15)) + + events: {} as { type: "FOO" } | { type: "BAR" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 31, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 33, 4)) + + "*": (ev) => { +>"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 34, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 35, 10)) + + ev.type; // should be 'FOO' | 'BAR' +>ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 37)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 35, 10)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 37)) + + }, + }, +}); + +interface MachineConfig2 { +>MachineConfig2 : Symbol(MachineConfig2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 41)) + + schema: { +>schema : Symbol(MachineConfig2.schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 59)) + + events: TEvent; +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 42, 11)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) + + }; + on?: { +>on : Symbol(MachineConfig2.on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 44, 4)) + + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>Uppercase : Symbol(Uppercase, Decl(lib.es5.d.ts, --, --)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 94)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) + + } & { + "*"?: Action; +>"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 47, 7)) +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) + + }; +} + +declare function createMachine2( +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 32)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 48)) + + config: MachineConfig2 +>config : Symbol(config, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 65)) +>MachineConfig2 : Symbol(MachineConfig2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 32)) + +): void; + +createMachine2({ +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 16)) + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 57, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 59, 4)) + + FOO: (ev) => { +>FOO : Symbol(FOO, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 60, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 61, 10)) + + ev.type; // should be 'FOO' +>ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 19)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 61, 10)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 19)) + + }, + }, +}); + +createMachine2({ +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 67, 16)) + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 68, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 70, 4)) + + "*": (ev) => { +>"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 71, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 72, 10)) + + ev.type; // should be 'FOO' | 'bar' +>ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 37)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 72, 10)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 37)) + + }, + }, +}); + +createMachine2({ +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 78, 16)) + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 79, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 80, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 80, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 81, 4)) + + bar: (ev) => { +>bar : Symbol(bar, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 82, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 83, 10)) + + ev // any +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 83, 10)) + + }, + }, +}); + +// repro from #49307#issuecomment-1143103607 + +declare function createSlice( +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 91, 29)) + + reducers: { [K: string]: (state: string) => void } & { +>reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 91, 32)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 92, 15)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 92, 28)) + + [K in keyof T]: object; +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 93, 5)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 91, 29)) + } +): void; + +createSlice({ +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) + + f(a) {}, +>f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 97, 13)) +>a : Symbol(a, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 98, 4)) + +}); + +// repro from #49307#issuecomment-1196014488 + +type Validate = T & { [K in keyof T]: object } +>Validate : Symbol(Validate, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 99, 3)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 14)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 14)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 26)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 14)) + +declare function f any>>(s: S, x: Validate): void; +>f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 49)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 19)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 21)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 48)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 19)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 67)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 19)) +>x : Symbol(x, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 72)) +>Validate : Symbol(Validate, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 99, 3)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 21)) + +f(0, { +>f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 49)) + + foo: s => s + 1, +>foo : Symbol(foo, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 106, 6)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 107, 6)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 107, 6)) + +}) + +// repro from 49307#issuecomment-1195858950 + +type SliceCaseReducers = Record State | void>; +>SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 108, 2)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 23)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 48)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 23)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 23)) + +type ValidateSliceCaseReducers> = ACR & { +>ValidateSliceCaseReducers : Symbol(ValidateSliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 79)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 31)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) +>SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 108, 2)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 31)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) + + [T in keyof ACR]: ACR[T] extends { +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 115, 3)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 115, 3)) + + reducer(s: S, action?: infer A): any; +>reducer : Symbol(reducer, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 115, 36)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 12)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 31)) +>action : Symbol(action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 17)) +>A : Symbol(A, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 32)) + } + ? { + prepare(...a: never[]): Omit; +>prepare : Symbol(prepare, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 118, 7)) +>a : Symbol(a, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 119, 16)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>A : Symbol(A, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 32)) + } + : {}; +}; + +declare function createSlice< +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) + + State, +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) + + CaseReducers extends SliceCaseReducers +>CaseReducers : Symbol(CaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 125, 8)) +>SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 108, 2)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) + +>(options: { +>options : Symbol(options, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 127, 2)) + + initialState: State | (() => State); +>initialState : Symbol(initialState, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 127, 12)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) + + reducers: ValidateSliceCaseReducers; +>reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 128, 38)) +>ValidateSliceCaseReducers : Symbol(ValidateSliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 79)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) +>CaseReducers : Symbol(CaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 125, 8)) + +}): void; + +export const clientSlice = createSlice({ +>clientSlice : Symbol(clientSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 132, 12)) +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) + + initialState: { +>initialState : Symbol(initialState, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 132, 40)) + + username: "", +>username : Symbol(username, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 133, 17)) + + isLoggedIn: false, +>isLoggedIn : Symbol(isLoggedIn, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 134, 17)) + + userId: "", +>userId : Symbol(userId, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 135, 22)) + + avatar: "", +>avatar : Symbol(avatar, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 136, 15)) + + }, + reducers: { +>reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 138, 4)) + + onClientUserChanged(state) {}, +>onClientUserChanged : Symbol(onClientUserChanged, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 139, 13)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 140, 24)) + + }, +}); + + diff --git a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types new file mode 100644 index 0000000000000..02d0173439a01 --- /dev/null +++ b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types @@ -0,0 +1,540 @@ +//// [tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts] //// + +=== contextualTypeFunctionObjectPropertyIntersection.ts === +// repro from #48812 + +type Action = (ev: TEvent) => void; +>Action : Action +> : ^^^^^^^^^^^^^^ +>type : string +> : ^^^^^^ +>ev : TEvent +> : ^^^^^^ + +interface MachineConfig { +>type : string +> : ^^^^^^ + + schema: { +>schema : { events: TEvent; } +> : ^^^^^^^^^^ ^^^ + + events: TEvent; +>events : TEvent +> : ^^^^^^ + + }; + on?: { +>on : ({ [K in TEvent["type"]]?: Action | undefined; } & { "*"?: Action; }) | undefined +> : ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + + [K in TEvent["type"]]?: Action; +>type : K +> : ^ + + } & { + "*"?: Action; +>"*" : Action | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ + + }; +} + +declare function createMachine( +>createMachine : (config: MachineConfig) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>type : string +> : ^^^^^^ + + config: MachineConfig +>config : MachineConfig +> : ^^^^^^^^^^^^^^^^^^^^^ + +): void; + +createMachine({ +>createMachine({ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { FOO: (ev) => { ev.type; // should be 'FOO' }, },}) : void +> : ^^^^ +>createMachine : (config: MachineConfig) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { FOO: (ev) => { ev.type; // should be 'FOO' }, },} : { schema: { events: { type: "FOO"; } | { type: "BAR"; }; }; on: { FOO: (ev: { type: "FOO"; }) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "BAR"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "BAR" }, } : { events: { type: "FOO"; } | { type: "BAR"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "BAR" }, +>events : { type: "FOO"; } | { type: "BAR"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "BAR" } : { type: "FOO"; } | { type: "BAR"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "BAR" +> : ^^^^^ + + }, + on: { +>on : { FOO: (ev: { type: "FOO"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>{ FOO: (ev) => { ev.type; // should be 'FOO' }, } : { FOO: (ev: { type: "FOO"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + FOO: (ev) => { +>FOO : (ev: { type: "FOO"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^ +>(ev) => { ev.type; // should be 'FOO' } : (ev: { type: "FOO"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^ +>ev : { type: "FOO"; } +> : ^^^^^^^^ ^^^ + + ev.type; // should be 'FOO' +>ev.type : "FOO" +> : ^^^^^ +>ev : { type: "FOO"; } +> : ^^^^^^^^ ^^^ +>type : "FOO" +> : ^^^^^ + + }, + }, +}); + +createMachine({ +>createMachine({ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'BAR' }, },}) : void +> : ^^^^ +>createMachine : (config: MachineConfig) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'BAR' }, },} : { schema: { events: { type: "FOO"; } | { type: "BAR"; }; }; on: { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "BAR"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "BAR" }, } : { events: { type: "FOO"; } | { type: "BAR"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "BAR" }, +>events : { type: "FOO"; } | { type: "BAR"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "BAR" } : { type: "FOO"; } | { type: "BAR"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "BAR" +> : ^^^^^ + + }, + on: { +>on : { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>{ "*": (ev) => { ev.type; // should be 'FOO' | 'BAR' }, } : { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + "*": (ev) => { +>"*" : (ev: { type: "FOO"; } | { type: "BAR"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +>(ev) => { ev.type; // should be 'FOO' | 'BAR' } : (ev: { type: "FOO"; } | { type: "BAR"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +>ev : { type: "FOO"; } | { type: "BAR"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ + + ev.type; // should be 'FOO' | 'BAR' +>ev.type : "FOO" | "BAR" +> : ^^^^^^^^^^^^^ +>ev : { type: "FOO"; } | { type: "BAR"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>type : "FOO" | "BAR" +> : ^^^^^^^^^^^^^ + + }, + }, +}); + +interface MachineConfig2 { +>type : string +> : ^^^^^^ + + schema: { +>schema : { events: TEvent; } +> : ^^^^^^^^^^ ^^^ + + events: TEvent; +>events : TEvent +> : ^^^^^^ + + }; + on?: { +>on : ({ [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action | undefined; } & { "*"?: Action; }) | undefined +> : ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; +>type : K +> : ^ + + } & { + "*"?: Action; +>"*" : Action | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ + + }; +} + +declare function createMachine2( +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>type : string +> : ^^^^^^ + + config: MachineConfig2 +>config : MachineConfig2 +> : ^^^^^^^^^^^^^^^^^^^^^^ + +): void; + +createMachine2({ +>createMachine2({ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { FOO: (ev) => { ev.type; // should be 'FOO' }, },}) : void +> : ^^^^ +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { FOO: (ev) => { ev.type; // should be 'FOO' }, },} : { schema: { events: { type: "FOO"; } | { type: "bar"; }; }; on: { FOO: (ev: { type: "FOO"; }) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "bar" }, } : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "bar" } : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "bar" +> : ^^^^^ + + }, + on: { +>on : { FOO: (ev: { type: "FOO"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>{ FOO: (ev) => { ev.type; // should be 'FOO' }, } : { FOO: (ev: { type: "FOO"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + FOO: (ev) => { +>FOO : (ev: { type: "FOO"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^ +>(ev) => { ev.type; // should be 'FOO' } : (ev: { type: "FOO"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^ +>ev : { type: "FOO"; } +> : ^^^^^^^^ ^^^ + + ev.type; // should be 'FOO' +>ev.type : "FOO" +> : ^^^^^ +>ev : { type: "FOO"; } +> : ^^^^^^^^ ^^^ +>type : "FOO" +> : ^^^^^ + + }, + }, +}); + +createMachine2({ +>createMachine2({ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'bar' }, },}) : void +> : ^^^^ +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'bar' }, },} : { schema: { events: { type: "FOO"; } | { type: "bar"; }; }; on: { "*": (ev: { type: "FOO"; } | { type: "bar"; }) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "bar" }, } : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "bar" } : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "bar" +> : ^^^^^ + + }, + on: { +>on : { "*": (ev: { type: "FOO"; } | { type: "bar"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>{ "*": (ev) => { ev.type; // should be 'FOO' | 'bar' }, } : { "*": (ev: { type: "FOO"; } | { type: "bar"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + "*": (ev) => { +>"*" : (ev: { type: "FOO"; } | { type: "bar"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +>(ev) => { ev.type; // should be 'FOO' | 'bar' } : (ev: { type: "FOO"; } | { type: "bar"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +>ev : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ + + ev.type; // should be 'FOO' | 'bar' +>ev.type : "FOO" | "bar" +> : ^^^^^^^^^^^^^ +>ev : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>type : "FOO" | "bar" +> : ^^^^^^^^^^^^^ + + }, + }, +}); + +createMachine2({ +>createMachine2({ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { bar: (ev) => { ev // any }, },}) : void +> : ^^^^ +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { bar: (ev) => { ev // any }, },} : { schema: { events: { type: "FOO"; } | { type: "bar"; }; }; on: { bar: (ev: any) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "bar" }, } : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "bar" } : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "bar" +> : ^^^^^ + + }, + on: { +>on : { bar: (ev: any) => void; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^ +>{ bar: (ev) => { ev // any }, } : { bar: (ev: any) => void; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^ + + bar: (ev) => { +>bar : (ev: any) => void +> : ^ ^^^^^^^^^^^^^^ +>(ev) => { ev // any } : (ev: any) => void +> : ^ ^^^^^^^^^^^^^^ +>ev : any +> : ^^^ + + ev // any +>ev : any +> : ^^^ + + }, + }, +}); + +// repro from #49307#issuecomment-1143103607 + +declare function createSlice( +>createSlice : { (reducers: { [K: string]: (state: string) => void; } & { [K in keyof T]: object; }): void; >(options: { initialState: State | (() => State); reducers: ValidateSliceCaseReducers; }): void; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^ ^^^ + + reducers: { [K: string]: (state: string) => void } & { +>reducers : { [K: string]: (state: string) => void; } & { [K in keyof T]: object; } +> : ^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>K : string +> : ^^^^^^ +>state : string +> : ^^^^^^ + + [K in keyof T]: object; + } +): void; + +createSlice({ +>createSlice({ f(a) {},}) : void +> : ^^^^ +>createSlice : { (reducers: { [K: string]: (state: string) => void; } & { [K in keyof T]: object; }): void; >(options: { initialState: State | (() => State); reducers: ValidateSliceCaseReducers; }): void; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^ ^^^ +>{ f(a) {},} : { f(a: string): void; } +> : ^^^^ ^^^^^^^^^^^^^^^^^^ + + f(a) {}, +>f : (a: string) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>a : string +> : ^^^^^^ + +}); + +// repro from #49307#issuecomment-1196014488 + +type Validate = T & { [K in keyof T]: object } +>Validate : Validate +> : ^^^^^^^^^^^ + +declare function f any>>(s: S, x: Validate): void; +>f : any>>(s: S, x: Validate) => void +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ +>state : S +> : ^ +>s : S +> : ^ +>x : Validate +> : ^^^^^^^^^^^ + +f(0, { +>f(0, { foo: s => s + 1,}) : void +> : ^^^^ +>f : any>>(s: S, x: Validate) => void +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ +>0 : 0 +> : ^ +>{ foo: s => s + 1,} : { foo: (s: number) => number; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ + + foo: s => s + 1, +>foo : (s: number) => number +> : ^ ^^^^^^^^^^^^^^^^^^^ +>s => s + 1 : (s: number) => number +> : ^ ^^^^^^^^^^^^^^^^^^^ +>s : number +> : ^^^^^^ +>s + 1 : number +> : ^^^^^^ +>s : number +> : ^^^^^^ +>1 : 1 +> : ^ + +}) + +// repro from 49307#issuecomment-1195858950 + +type SliceCaseReducers = Record State | void>; +>SliceCaseReducers : SliceCaseReducers +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>state : State +> : ^^^^^ + +type ValidateSliceCaseReducers> = ACR & { +>ValidateSliceCaseReducers : ValidateSliceCaseReducers +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + [T in keyof ACR]: ACR[T] extends { + reducer(s: S, action?: infer A): any; +>reducer : (s: S, action?: infer A) => any +> : ^ ^^ ^^ ^^^ ^^^^^ +>s : S +> : ^ +>action : A | undefined +> : ^^^^^^^^^^^^^ + } + ? { + prepare(...a: never[]): Omit; +>prepare : (...a: never[]) => Omit +> : ^^^^ ^^ ^^^^^ +>a : never[] +> : ^^^^^^^ + } + : {}; +}; + +declare function createSlice< +>createSlice : { (reducers: { [K: string]: (state: string) => void; } & { [K in keyof T]: object; }): void; >(options: { initialState: State | (() => State); reducers: ValidateSliceCaseReducers; }): void; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^ ^^^ + + State, + CaseReducers extends SliceCaseReducers +>(options: { +>options : { initialState: State | (() => State); reducers: ValidateSliceCaseReducers; } +> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^ ^^^ + + initialState: State | (() => State); +>initialState : State | (() => State) +> : ^^^^^^^^^^^^^^^ ^ + + reducers: ValidateSliceCaseReducers; +>reducers : ValidateSliceCaseReducers +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +}): void; + +export const clientSlice = createSlice({ +>clientSlice : void +> : ^^^^ +>createSlice({ initialState: { username: "", isLoggedIn: false, userId: "", avatar: "", }, reducers: { onClientUserChanged(state) {}, },}) : void +> : ^^^^ +>createSlice : { (reducers: { [K: string]: (state: string) => void; } & { [K in keyof T]: object; }): void; >(options: { initialState: State | (() => State); reducers: ValidateSliceCaseReducers; }): void; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^ ^^^ +>{ initialState: { username: "", isLoggedIn: false, userId: "", avatar: "", }, reducers: { onClientUserChanged(state) {}, },} : { initialState: { username: string; isLoggedIn: false; userId: string; avatar: string; }; reducers: { onClientUserChanged(state: { username: string; isLoggedIn: boolean; userId: string; avatar: string; }): void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + initialState: { +>initialState : { username: string; isLoggedIn: false; userId: string; avatar: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ username: "", isLoggedIn: false, userId: "", avatar: "", } : { username: string; isLoggedIn: false; userId: string; avatar: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + username: "", +>username : string +> : ^^^^^^ +>"" : "" +> : ^^ + + isLoggedIn: false, +>isLoggedIn : false +> : ^^^^^ +>false : false +> : ^^^^^ + + userId: "", +>userId : string +> : ^^^^^^ +>"" : "" +> : ^^ + + avatar: "", +>avatar : string +> : ^^^^^^ +>"" : "" +> : ^^ + + }, + reducers: { +>reducers : { onClientUserChanged(state: { username: string; isLoggedIn: boolean; userId: string; avatar: string; }): void; } +> : ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ onClientUserChanged(state) {}, } : { onClientUserChanged(state: { username: string; isLoggedIn: boolean; userId: string; avatar: string; }): void; } +> : ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + onClientUserChanged(state) {}, +>onClientUserChanged : (state: { username: string; isLoggedIn: boolean; userId: string; avatar: string; }) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>state : { username: string; isLoggedIn: boolean; userId: string; avatar: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + }, +}); + + diff --git a/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.symbols b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.symbols new file mode 100644 index 0000000000000..8f282ef5ad271 --- /dev/null +++ b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.symbols @@ -0,0 +1,117 @@ +//// [tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts] //// + +=== contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts === +type IntrinsicElements = { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 0, 0)) + + div: { +>div : Symbol(div, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 0, 26)) + + onChange: (ev: Event) => void; +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 1, 8)) +>ev : Symbol(ev, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 2, 15)) +>Event : Symbol(Event, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + + }; + span: { +>span : Symbol(span, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 3, 4)) + + onChange: (ev: Event) => void; +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 4, 9)) +>ev : Symbol(ev, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 5, 15)) +>Event : Symbol(Event, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + + }; +}; + +type ElementType = keyof IntrinsicElements; +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 7, 2)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 0, 0)) + +let DEFAULT_TABS_TAG = "div" as const; +>DEFAULT_TABS_TAG : Symbol(DEFAULT_TABS_TAG, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 11, 3)) +>const : Symbol(const) + +type Props = Omit< +>Props : Symbol(Props, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 11, 38)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 13, 11)) +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 7, 2)) +>Overrides : Symbol(Overrides, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 13, 36)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) + + IntrinsicElements[TTag], +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 0, 0)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 13, 11)) + + keyof Overrides +>Overrides : Symbol(Overrides, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 13, 36)) + +> & + Overrides; +>Overrides : Symbol(Overrides, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 13, 36)) + +type TabGroupProps = Props< +>TabGroupProps : Symbol(TabGroupProps, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 17, 12)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 19, 19)) +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 7, 2)) +>DEFAULT_TABS_TAG : Symbol(DEFAULT_TABS_TAG, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 11, 3)) +>Props : Symbol(Props, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 11, 38)) + + TTag, +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 19, 19)) + { + defaultIndex?: number; +>defaultIndex : Symbol(defaultIndex, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 21, 3)) + + onChange?: (index: number) => void; +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 22, 26)) +>index : Symbol(index, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 23, 16)) + + selectedIndex?: number; +>selectedIndex : Symbol(selectedIndex, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 23, 39)) + + vertical?: boolean; +>vertical : Symbol(vertical, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 24, 27)) + + manual?: boolean; +>manual : Symbol(manual, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 25, 23)) + } +>; + +interface _internal_ComponentTabGroup { +>_internal_ComponentTabGroup : Symbol(_internal_ComponentTabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 28, 2)) + + ( +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 31, 3)) +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 7, 2)) +>DEFAULT_TABS_TAG : Symbol(DEFAULT_TABS_TAG, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 11, 3)) + + props: TabGroupProps, +>props : Symbol(props, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 31, 55)) +>TabGroupProps : Symbol(TabGroupProps, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 17, 12)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 31, 3)) + + ): null; +} + +declare let TabGroup: _internal_ComponentTabGroup; +>TabGroup : Symbol(TabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 36, 11)) +>_internal_ComponentTabGroup : Symbol(_internal_ComponentTabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 28, 2)) + +TabGroup({ +>TabGroup : Symbol(TabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 36, 11)) + + defaultIndex: 0, +>defaultIndex : Symbol(defaultIndex, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 38, 10)) + + onChange: (index) => { +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 39, 18)) +>index : Symbol(index, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 40, 13)) + + const i: number = index; +>i : Symbol(i, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 41, 9)) +>index : Symbol(index, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts, 40, 13)) + + }, +}); + diff --git a/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.types b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.types new file mode 100644 index 0000000000000..4b214b1a19519 --- /dev/null +++ b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.types @@ -0,0 +1,131 @@ +//// [tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts] //// + +=== contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts === +type IntrinsicElements = { +>IntrinsicElements : IntrinsicElements +> : ^^^^^^^^^^^^^^^^^ + + div: { +>div : { onChange: (ev: Event) => void; } +> : ^^^^^^^^^^^^ ^^^ + + onChange: (ev: Event) => void; +>onChange : (ev: Event) => void +> : ^ ^^ ^^^^^ +>ev : Event +> : ^^^^^ + + }; + span: { +>span : { onChange: (ev: Event) => void; } +> : ^^^^^^^^^^^^ ^^^ + + onChange: (ev: Event) => void; +>onChange : (ev: Event) => void +> : ^ ^^ ^^^^^ +>ev : Event +> : ^^^^^ + + }; +}; + +type ElementType = keyof IntrinsicElements; +>ElementType : keyof IntrinsicElements +> : ^^^^^^^^^^^^^^^^^^^^^^^ + +let DEFAULT_TABS_TAG = "div" as const; +>DEFAULT_TABS_TAG : "div" +> : ^^^^^ +>"div" as const : "div" +> : ^^^^^ +>"div" : "div" +> : ^^^^^ + +type Props = Omit< +>Props : Props +> : ^^^^^^^^^^^^^^^^^^^^^^ + + IntrinsicElements[TTag], + keyof Overrides +> & + Overrides; + +type TabGroupProps = Props< +>TabGroupProps : TabGroupProps +> : ^^^^^^^^^^^^^^^^^^^ +>DEFAULT_TABS_TAG : "div" +> : ^^^^^ + + TTag, + { + defaultIndex?: number; +>defaultIndex : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + onChange?: (index: number) => void; +>onChange : ((index: number) => void) | undefined +> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^ +>index : number +> : ^^^^^^ + + selectedIndex?: number; +>selectedIndex : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + vertical?: boolean; +>vertical : boolean | undefined +> : ^^^^^^^^^^^^^^^^^^^ + + manual?: boolean; +>manual : boolean | undefined +> : ^^^^^^^^^^^^^^^^^^^ + } +>; + +interface _internal_ComponentTabGroup { + ( +>DEFAULT_TABS_TAG : "div" +> : ^^^^^ + + props: TabGroupProps, +>props : TabGroupProps +> : ^^^^^^^^^^^^^^^^^^^ + + ): null; +} + +declare let TabGroup: _internal_ComponentTabGroup; +>TabGroup : _internal_ComponentTabGroup +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +TabGroup({ +>TabGroup({ defaultIndex: 0, onChange: (index) => { const i: number = index; },}) : null +> : ^^^^ +>TabGroup : _internal_ComponentTabGroup +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ defaultIndex: 0, onChange: (index) => { const i: number = index; },} : { defaultIndex: number; onChange: (index: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + defaultIndex: 0, +>defaultIndex : number +> : ^^^^^^ +>0 : 0 +> : ^ + + onChange: (index) => { +>onChange : (index: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(index) => { const i: number = index; } : (index: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>index : number +> : ^^^^^^ + + const i: number = index; +>i : number +> : ^^^^^^ +>index : number +> : ^^^^^^ + + }, +}); + diff --git a/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.errors.txt b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.errors.txt new file mode 100644 index 0000000000000..4313cb5df1d02 --- /dev/null +++ b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.errors.txt @@ -0,0 +1,35 @@ +contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts(24,3): error TS2322: Type '(_: any) => string' is not assignable to type 'never'. +contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts(24,7): error TS7006: Parameter '_' implicitly has an 'any' type. + + +==== contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts (2 errors) ==== + type Tags = P extends Record ? X : never; + + declare const typeTags: () => < + P extends { + readonly [Tag in Tags<"_tag", I> & string]: ( + _: Extract, + ) => any; + } & { readonly [Tag in Exclude>]: never }, + >( + fields: P, + ) => unknown; + + type Value = { _tag: "A"; a: number } | { _tag: "B"; b: number }; + const matcher = typeTags(); + + matcher({ + A: (_) => _.a, + B: (_) => "fail", + }); + + matcher({ + A: (_) => _.a, + B: (_) => "fail", + C: (_) => "fail", + ~ +!!! error TS2322: Type '(_: any) => string' is not assignable to type 'never'. + ~ +!!! error TS7006: Parameter '_' implicitly has an 'any' type. + }); + \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.symbols b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.symbols new file mode 100644 index 0000000000000..c175ed578a05a --- /dev/null +++ b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.symbols @@ -0,0 +1,95 @@ +//// [tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts] //// + +=== contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts === +type Tags = P extends Record ? X : never; +>Tags : Symbol(Tags, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 0)) +>D : Symbol(D, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 10)) +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 27)) +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 27)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>D : Symbol(D, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 10)) +>X : Symbol(X, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 58)) +>X : Symbol(X, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 58)) + +declare const typeTags: () => < +>typeTags : Symbol(typeTags, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 13)) +>I : Symbol(I, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 25)) + + P extends { +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 34)) + + readonly [Tag in Tags<"_tag", I> & string]: ( +>Tag : Symbol(Tag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 4, 14)) +>Tags : Symbol(Tags, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 0)) +>I : Symbol(I, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 25)) + + _: Extract, +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 4, 49)) +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) +>I : Symbol(I, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 25)) +>_tag : Symbol(_tag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 5, 21)) +>Tag : Symbol(Tag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 4, 14)) + + ) => any; + } & { readonly [Tag in Exclude>]: never }, +>Tag : Symbol(Tag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 7, 18)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 34)) +>Tags : Symbol(Tags, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 0, 0)) +>I : Symbol(I, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 25)) + +>( + fields: P, +>fields : Symbol(fields, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 8, 2)) +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 34)) + +) => unknown; + +type Value = { _tag: "A"; a: number } | { _tag: "B"; b: number }; +>Value : Symbol(Value, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 10, 13)) +>_tag : Symbol(_tag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 14)) +>a : Symbol(a, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 25)) +>_tag : Symbol(_tag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 41)) +>b : Symbol(b, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 52)) + +const matcher = typeTags(); +>matcher : Symbol(matcher, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 13, 5)) +>typeTags : Symbol(typeTags, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 2, 13)) +>Value : Symbol(Value, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 10, 13)) + +matcher({ +>matcher : Symbol(matcher, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 13, 5)) + + A: (_) => _.a, +>A : Symbol(A, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 15, 9)) +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 16, 6)) +>_.a : Symbol(a, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 25)) +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 16, 6)) +>a : Symbol(a, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 25)) + + B: (_) => "fail", +>B : Symbol(B, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 16, 16)) +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 17, 6)) + +}); + +matcher({ +>matcher : Symbol(matcher, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 13, 5)) + + A: (_) => _.a, +>A : Symbol(A, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 20, 9)) +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 21, 6)) +>_.a : Symbol(a, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 25)) +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 21, 6)) +>a : Symbol(a, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 12, 25)) + + B: (_) => "fail", +>B : Symbol(B, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 21, 16)) +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 22, 6)) + + C: (_) => "fail", +>C : Symbol(C, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 22, 19)) +>_ : Symbol(_, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts, 23, 6)) + +}); + diff --git a/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.types b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.types new file mode 100644 index 0000000000000..26b6c8f492ad7 --- /dev/null +++ b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.types @@ -0,0 +1,126 @@ +//// [tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts] //// + +=== contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts === +type Tags = P extends Record ? X : never; +>Tags : Tags +> : ^^^^^^^^^^ + +declare const typeTags: () => < +>typeTags : () =>

& string]: (_: Extract) => any; } & { readonly [Tag in Exclude>]: never; }>(fields: P) => unknown +> : ^ ^^^^^^^ + + P extends { + readonly [Tag in Tags<"_tag", I> & string]: ( + _: Extract, +>_ : Extract +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ +>_tag : Tag +> : ^^^ + + ) => any; + } & { readonly [Tag in Exclude>]: never }, +>( + fields: P, +>fields : P +> : ^ + +) => unknown; + +type Value = { _tag: "A"; a: number } | { _tag: "B"; b: number }; +>Value : Value +> : ^^^^^ +>_tag : "A" +> : ^^^ +>a : number +> : ^^^^^^ +>_tag : "B" +> : ^^^ +>b : number +> : ^^^^^^ + +const matcher = typeTags(); +>matcher :

any; readonly B: (_: { _tag: "B"; b: number; }) => any; } & { readonly [Tag in Exclude]: never; }>(fields: P) => unknown +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ +>typeTags() :

any; readonly B: (_: { _tag: "B"; b: number; }) => any; } & { readonly [Tag in Exclude]: never; }>(fields: P) => unknown +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ +>typeTags : () =>

& string]: (_: Extract) => any; } & { readonly [Tag in Exclude>]: never; }>(fields: P) => unknown +> : ^ ^^^^^^^ + +matcher({ +>matcher({ A: (_) => _.a, B: (_) => "fail",}) : unknown +> : ^^^^^^^ +>matcher :

any; readonly B: (_: { _tag: "B"; b: number; }) => any; } & { readonly [Tag in Exclude]: never; }>(fields: P) => unknown +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ +>{ A: (_) => _.a, B: (_) => "fail",} : { A: (_: { _tag: "A"; a: number; }) => number; B: (_: { _tag: "B"; b: number; }) => string; } +> : ^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^ + + A: (_) => _.a, +>A : (_: { _tag: "A"; a: number; }) => number +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>(_) => _.a : (_: { _tag: "A"; a: number; }) => number +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>_ : { _tag: "A"; a: number; } +> : ^^^^^^^^ ^^^^^ ^^^ +>_.a : number +> : ^^^^^^ +>_ : { _tag: "A"; a: number; } +> : ^^^^^^^^ ^^^^^ ^^^ +>a : number +> : ^^^^^^ + + B: (_) => "fail", +>B : (_: { _tag: "B"; b: number; }) => string +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>(_) => "fail" : (_: { _tag: "B"; b: number; }) => string +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>_ : { _tag: "B"; b: number; } +> : ^^^^^^^^ ^^^^^ ^^^ +>"fail" : "fail" +> : ^^^^^^ + +}); + +matcher({ +>matcher({ A: (_) => _.a, B: (_) => "fail", C: (_) => "fail",}) : unknown +> : ^^^^^^^ +>matcher :

any; readonly B: (_: { _tag: "B"; b: number; }) => any; } & { readonly [Tag in Exclude]: never; }>(fields: P) => unknown +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ +>{ A: (_) => _.a, B: (_) => "fail", C: (_) => "fail",} : { A: (_: { _tag: "A"; a: number; }) => number; B: (_: { _tag: "B"; b: number; }) => string; C: (_: any) => string; } +> : ^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ + + A: (_) => _.a, +>A : (_: { _tag: "A"; a: number; }) => number +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>(_) => _.a : (_: { _tag: "A"; a: number; }) => number +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>_ : { _tag: "A"; a: number; } +> : ^^^^^^^^ ^^^^^ ^^^ +>_.a : number +> : ^^^^^^ +>_ : { _tag: "A"; a: number; } +> : ^^^^^^^^ ^^^^^ ^^^ +>a : number +> : ^^^^^^ + + B: (_) => "fail", +>B : (_: { _tag: "B"; b: number; }) => string +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>(_) => "fail" : (_: { _tag: "B"; b: number; }) => string +> : ^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^ +>_ : { _tag: "B"; b: number; } +> : ^^^^^^^^ ^^^^^ ^^^ +>"fail" : "fail" +> : ^^^^^^ + + C: (_) => "fail", +>C : (_: any) => string +> : ^ ^^^^^^^^^^^^^^^^ +>(_) => "fail" : (_: any) => string +> : ^ ^^^^^^^^^^^^^^^^ +>_ : any +> : ^^^ +>"fail" : "fail" +> : ^^^^^^ + +}); + diff --git a/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.symbols b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.symbols new file mode 100644 index 0000000000000..ba631da07b54d --- /dev/null +++ b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.symbols @@ -0,0 +1,129 @@ +//// [tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts] //// + +=== contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts === +type MappedOmit = { [P in keyof T as Exclude]: T[P]; } +>MappedOmit : Symbol(MappedOmit, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 0)) +>T : Symbol(T, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 16)) +>K : Symbol(K, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 18)) +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 45)) +>T : Symbol(T, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 16)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 45)) +>K : Symbol(K, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 18)) +>T : Symbol(T, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 16)) +>P : Symbol(P, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 45)) + +type IntrinsicElements = { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 84)) + + div: { +>div : Symbol(div, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 2, 26)) + + onChange: (ev: Event) => void; +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 3, 8)) +>ev : Symbol(ev, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 4, 15)) +>Event : Symbol(Event, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + + }; + span: { +>span : Symbol(span, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 5, 4)) + + onChange: (ev: Event) => void; +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 6, 9)) +>ev : Symbol(ev, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 7, 15)) +>Event : Symbol(Event, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + + }; +}; + +type ElementType = keyof IntrinsicElements; +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 9, 2)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 84)) + +let DEFAULT_TABS_TAG = "div" as const; +>DEFAULT_TABS_TAG : Symbol(DEFAULT_TABS_TAG, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 13, 3)) +>const : Symbol(const) + +type Props = MappedOmit< +>Props : Symbol(Props, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 13, 38)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 15, 11)) +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 9, 2)) +>Overrides : Symbol(Overrides, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 15, 36)) +>MappedOmit : Symbol(MappedOmit, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 0)) + + IntrinsicElements[TTag], +>IntrinsicElements : Symbol(IntrinsicElements, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 0, 84)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 15, 11)) + + keyof Overrides +>Overrides : Symbol(Overrides, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 15, 36)) + +> & + Overrides; +>Overrides : Symbol(Overrides, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 15, 36)) + +type TabGroupProps = Props< +>TabGroupProps : Symbol(TabGroupProps, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 19, 12)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 21, 19)) +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 9, 2)) +>DEFAULT_TABS_TAG : Symbol(DEFAULT_TABS_TAG, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 13, 3)) +>Props : Symbol(Props, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 13, 38)) + + TTag, +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 21, 19)) + { + defaultIndex?: number; +>defaultIndex : Symbol(defaultIndex, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 23, 3)) + + onChange?: (index: number) => void; +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 24, 26)) +>index : Symbol(index, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 25, 16)) + + selectedIndex?: number; +>selectedIndex : Symbol(selectedIndex, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 25, 39)) + + vertical?: boolean; +>vertical : Symbol(vertical, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 26, 27)) + + manual?: boolean; +>manual : Symbol(manual, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 27, 23)) + } +>; + +interface _internal_ComponentTabGroup { +>_internal_ComponentTabGroup : Symbol(_internal_ComponentTabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 30, 2)) + + ( +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 33, 3)) +>ElementType : Symbol(ElementType, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 9, 2)) +>DEFAULT_TABS_TAG : Symbol(DEFAULT_TABS_TAG, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 13, 3)) + + props: TabGroupProps, +>props : Symbol(props, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 33, 55)) +>TabGroupProps : Symbol(TabGroupProps, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 19, 12)) +>TTag : Symbol(TTag, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 33, 3)) + + ): null; +} + +declare let TabGroup: _internal_ComponentTabGroup; +>TabGroup : Symbol(TabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 38, 11)) +>_internal_ComponentTabGroup : Symbol(_internal_ComponentTabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 30, 2)) + +TabGroup({ +>TabGroup : Symbol(TabGroup, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 38, 11)) + + defaultIndex: 0, +>defaultIndex : Symbol(defaultIndex, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 40, 10)) + + onChange: (index) => { +>onChange : Symbol(onChange, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 41, 18)) +>index : Symbol(index, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 42, 13)) + + const i: number = index; +>i : Symbol(i, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 43, 9)) +>index : Symbol(index, Decl(contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts, 42, 13)) + + }, +}); + diff --git a/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.types b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.types new file mode 100644 index 0000000000000..b397cc9ae29cd --- /dev/null +++ b/tests/baselines/reference/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.types @@ -0,0 +1,135 @@ +//// [tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts] //// + +=== contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts === +type MappedOmit = { [P in keyof T as Exclude]: T[P]; } +>MappedOmit : MappedOmit +> : ^^^^^^^^^^^^^^^^ + +type IntrinsicElements = { +>IntrinsicElements : IntrinsicElements +> : ^^^^^^^^^^^^^^^^^ + + div: { +>div : { onChange: (ev: Event) => void; } +> : ^^^^^^^^^^^^ ^^^ + + onChange: (ev: Event) => void; +>onChange : (ev: Event) => void +> : ^ ^^ ^^^^^ +>ev : Event +> : ^^^^^ + + }; + span: { +>span : { onChange: (ev: Event) => void; } +> : ^^^^^^^^^^^^ ^^^ + + onChange: (ev: Event) => void; +>onChange : (ev: Event) => void +> : ^ ^^ ^^^^^ +>ev : Event +> : ^^^^^ + + }; +}; + +type ElementType = keyof IntrinsicElements; +>ElementType : keyof IntrinsicElements +> : ^^^^^^^^^^^^^^^^^^^^^^^ + +let DEFAULT_TABS_TAG = "div" as const; +>DEFAULT_TABS_TAG : "div" +> : ^^^^^ +>"div" as const : "div" +> : ^^^^^ +>"div" : "div" +> : ^^^^^ + +type Props = MappedOmit< +>Props : Props +> : ^^^^^^^^^^^^^^^^^^^^^^ + + IntrinsicElements[TTag], + keyof Overrides +> & + Overrides; + +type TabGroupProps = Props< +>TabGroupProps : TabGroupProps +> : ^^^^^^^^^^^^^^^^^^^ +>DEFAULT_TABS_TAG : "div" +> : ^^^^^ + + TTag, + { + defaultIndex?: number; +>defaultIndex : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + onChange?: (index: number) => void; +>onChange : ((index: number) => void) | undefined +> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^ +>index : number +> : ^^^^^^ + + selectedIndex?: number; +>selectedIndex : number | undefined +> : ^^^^^^^^^^^^^^^^^^ + + vertical?: boolean; +>vertical : boolean | undefined +> : ^^^^^^^^^^^^^^^^^^^ + + manual?: boolean; +>manual : boolean | undefined +> : ^^^^^^^^^^^^^^^^^^^ + } +>; + +interface _internal_ComponentTabGroup { + ( +>DEFAULT_TABS_TAG : "div" +> : ^^^^^ + + props: TabGroupProps, +>props : TabGroupProps +> : ^^^^^^^^^^^^^^^^^^^ + + ): null; +} + +declare let TabGroup: _internal_ComponentTabGroup; +>TabGroup : _internal_ComponentTabGroup +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +TabGroup({ +>TabGroup({ defaultIndex: 0, onChange: (index) => { const i: number = index; },}) : null +> : ^^^^ +>TabGroup : _internal_ComponentTabGroup +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ defaultIndex: 0, onChange: (index) => { const i: number = index; },} : { defaultIndex: number; onChange: (index: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + defaultIndex: 0, +>defaultIndex : number +> : ^^^^^^ +>0 : 0 +> : ^ + + onChange: (index) => { +>onChange : (index: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(index) => { const i: number = index; } : (index: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>index : number +> : ^^^^^^ + + const i: number = index; +>i : number +> : ^^^^^^ +>index : number +> : ^^^^^^ + + }, +}); + diff --git a/tests/baselines/reference/contextuallyTypedJsxAttribute2.symbols b/tests/baselines/reference/contextuallyTypedJsxAttribute2.symbols new file mode 100644 index 0000000000000..0d9415509ce8e --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedJsxAttribute2.symbols @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/contextuallyTypedJsxAttribute2.tsx] //// + +=== contextuallyTypedJsxAttribute2.tsx === +/// + +import React from "react"; +>React : Symbol(React, Decl(contextuallyTypedJsxAttribute2.tsx, 2, 6)) + +import { ComponentPropsWithRef, ElementType } from "react"; +>ComponentPropsWithRef : Symbol(ComponentPropsWithRef, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 8)) +>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31)) + +function UnwrappedLink( +>UnwrappedLink : Symbol(UnwrappedLink, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 59)) +>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 23)) +>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31)) +>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31)) + + props: Omit, "as">, +>props : Symbol(props, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 60)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>ComponentPropsWithRef : Symbol(ComponentPropsWithRef, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 8)) +>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31)) +>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 23)) +>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 5, 23)) + +) { + return ; +>a : Symbol(JSX.IntrinsicElements.a, Decl(react16.d.ts, 2516, 41)) +>a : Symbol(JSX.IntrinsicElements.a, Decl(react16.d.ts, 2516, 41)) +} + + {}} />; +>UnwrappedLink : Symbol(UnwrappedLink, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 59)) +>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 14)) +>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 25)) + +function UnwrappedLink2( +>UnwrappedLink2 : Symbol(UnwrappedLink2, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 38)) +>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24)) +>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31)) +>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31)) + + props: Omit, "as"> & { +>props : Symbol(props, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 61)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>ComponentPropsWithRef : Symbol(ComponentPropsWithRef, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 8)) +>ElementType : Symbol(ElementType, Decl(contextuallyTypedJsxAttribute2.tsx, 3, 31)) +>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24)) +>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24)) + + as?: T; +>as : Symbol(as, Decl(contextuallyTypedJsxAttribute2.tsx, 14, 79)) +>T : Symbol(T, Decl(contextuallyTypedJsxAttribute2.tsx, 13, 24)) + + }, +) { + return ; +>a : Symbol(JSX.IntrinsicElements.a, Decl(react16.d.ts, 2516, 41)) +>a : Symbol(JSX.IntrinsicElements.a, Decl(react16.d.ts, 2516, 41)) +} + + {}} />; +>UnwrappedLink2 : Symbol(UnwrappedLink2, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 38)) +>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 21, 15)) +>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 21, 26)) + + {}} />; +>UnwrappedLink2 : Symbol(UnwrappedLink2, Decl(contextuallyTypedJsxAttribute2.tsx, 11, 38)) +>as : Symbol(as, Decl(contextuallyTypedJsxAttribute2.tsx, 22, 15)) +>onClick : Symbol(onClick, Decl(contextuallyTypedJsxAttribute2.tsx, 22, 27)) +>e : Symbol(e, Decl(contextuallyTypedJsxAttribute2.tsx, 22, 38)) + diff --git a/tests/baselines/reference/contextuallyTypedJsxAttribute2.types b/tests/baselines/reference/contextuallyTypedJsxAttribute2.types new file mode 100644 index 0000000000000..119033445a3af --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedJsxAttribute2.types @@ -0,0 +1,100 @@ +//// [tests/cases/compiler/contextuallyTypedJsxAttribute2.tsx] //// + +=== Performance Stats === +Assignability cache: 5,000 +Type Count: 10,000 +Instantiation count: 250,000 +Symbol count: 100,000 + +=== contextuallyTypedJsxAttribute2.tsx === +/// + +import React from "react"; +>React : typeof React +> : ^^^^^^^^^^^^ + +import { ComponentPropsWithRef, ElementType } from "react"; +>ComponentPropsWithRef : any +> : ^^^ +>ElementType : any +> : ^^^ + +function UnwrappedLink( +>UnwrappedLink : (props: Omit, "as">) => JSX.Element +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^ + + props: Omit, "as">, +>props : Omit, "as"> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +) { + return ; +> : JSX.Element +> : ^^^^^^^^^^^ +>a : any +> : ^^^ +>a : any +> : ^^^ +} + + {}} />; +> {}} /> : JSX.Element +> : ^^^^^^^^^^^ +>UnwrappedLink : (props: Omit, "as">) => JSX.Element +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^ +>onClick : (e: React.MouseEvent) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(e) => {} : (e: React.MouseEvent) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>e : React.MouseEvent +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +function UnwrappedLink2( +>UnwrappedLink2 : (props: Omit, "as"> & { as?: T; }) => JSX.Element +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^ + + props: Omit, "as"> & { +>props : Omit, "as"> & { as?: T; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ + + as?: T; +>as : T | undefined +> : ^^^^^^^^^^^^^ + + }, +) { + return ; +> : JSX.Element +> : ^^^^^^^^^^^ +>a : any +> : ^^^ +>a : any +> : ^^^ +} + + {}} />; +> {}} /> : JSX.Element +> : ^^^^^^^^^^^ +>UnwrappedLink2 : (props: Omit, "as"> & { as?: T; }) => JSX.Element +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^ +>onClick : (e: React.MouseEvent) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(e) => {} : (e: React.MouseEvent) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>e : React.MouseEvent +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + {}} />; +> {}} /> : JSX.Element +> : ^^^^^^^^^^^ +>UnwrappedLink2 : (props: Omit, "as"> & { as?: T; }) => JSX.Element +> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^ +>as : "button" +> : ^^^^^^^^ +>onClick : (e: React.MouseEvent) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(e) => {} : (e: React.MouseEvent) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>e : React.MouseEvent +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/reverseMappedIntersectionInference1.symbols b/tests/baselines/reference/reverseMappedIntersectionInference1.symbols new file mode 100644 index 0000000000000..93bf0ed99c21c --- /dev/null +++ b/tests/baselines/reference/reverseMappedIntersectionInference1.symbols @@ -0,0 +1,121 @@ +//// [tests/cases/compiler/reverseMappedIntersectionInference1.ts] //// + +=== reverseMappedIntersectionInference1.ts === +type Results = { +>Results : Symbol(Results, Decl(reverseMappedIntersectionInference1.ts, 0, 0)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference1.ts, 0, 13)) + + [K in keyof T]: { +>K : Symbol(K, Decl(reverseMappedIntersectionInference1.ts, 1, 3)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference1.ts, 0, 13)) + + data: T[K]; +>data : Symbol(data, Decl(reverseMappedIntersectionInference1.ts, 1, 19)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference1.ts, 0, 13)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference1.ts, 1, 3)) + + onSuccess: (data: T[K]) => void; +>onSuccess : Symbol(onSuccess, Decl(reverseMappedIntersectionInference1.ts, 2, 15)) +>data : Symbol(data, Decl(reverseMappedIntersectionInference1.ts, 3, 16)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference1.ts, 0, 13)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference1.ts, 1, 3)) + + }; +}; + +type Errors = { +>Errors : Symbol(Errors, Decl(reverseMappedIntersectionInference1.ts, 5, 2)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference1.ts, 7, 12)) + + [K in keyof E]: { +>K : Symbol(K, Decl(reverseMappedIntersectionInference1.ts, 8, 3)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference1.ts, 7, 12)) + + error: E[K]; +>error : Symbol(error, Decl(reverseMappedIntersectionInference1.ts, 8, 19)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference1.ts, 7, 12)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference1.ts, 8, 3)) + + onError: (data: E[K]) => void; +>onError : Symbol(onError, Decl(reverseMappedIntersectionInference1.ts, 9, 16)) +>data : Symbol(data, Decl(reverseMappedIntersectionInference1.ts, 10, 14)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference1.ts, 7, 12)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference1.ts, 8, 3)) + + }; +}; + +declare function withKeyedObj( +>withKeyedObj : Symbol(withKeyedObj, Decl(reverseMappedIntersectionInference1.ts, 12, 2)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference1.ts, 14, 30)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference1.ts, 14, 32)) + + arg: Results & Errors +>arg : Symbol(arg, Decl(reverseMappedIntersectionInference1.ts, 14, 36)) +>Results : Symbol(Results, Decl(reverseMappedIntersectionInference1.ts, 0, 0)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference1.ts, 14, 30)) +>Errors : Symbol(Errors, Decl(reverseMappedIntersectionInference1.ts, 5, 2)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference1.ts, 14, 32)) + +): [T, E]; +>T : Symbol(T, Decl(reverseMappedIntersectionInference1.ts, 14, 30)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference1.ts, 14, 32)) + +const res = withKeyedObj({ +>res : Symbol(res, Decl(reverseMappedIntersectionInference1.ts, 18, 5)) +>withKeyedObj : Symbol(withKeyedObj, Decl(reverseMappedIntersectionInference1.ts, 12, 2)) + + a: { +>a : Symbol(a, Decl(reverseMappedIntersectionInference1.ts, 18, 26)) + + data: "foo", +>data : Symbol(data, Decl(reverseMappedIntersectionInference1.ts, 19, 6)) + + onSuccess: (dataArg) => { +>onSuccess : Symbol(onSuccess, Decl(reverseMappedIntersectionInference1.ts, 20, 16)) +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference1.ts, 21, 16)) + + dataArg; +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference1.ts, 21, 16)) + + }, + error: 404, +>error : Symbol(error, Decl(reverseMappedIntersectionInference1.ts, 23, 6)) + + onError: (errorArg) => { +>onError : Symbol(onError, Decl(reverseMappedIntersectionInference1.ts, 24, 15)) +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference1.ts, 25, 14)) + + errorArg; +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference1.ts, 25, 14)) + + }, + }, + b: { +>b : Symbol(b, Decl(reverseMappedIntersectionInference1.ts, 28, 4)) + + data: true, +>data : Symbol(data, Decl(reverseMappedIntersectionInference1.ts, 29, 6)) + + onSuccess: (dataArg) => { +>onSuccess : Symbol(onSuccess, Decl(reverseMappedIntersectionInference1.ts, 30, 15)) +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference1.ts, 31, 16)) + + dataArg; +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference1.ts, 31, 16)) + + }, + error: 500, +>error : Symbol(error, Decl(reverseMappedIntersectionInference1.ts, 33, 6)) + + onError: (errorArg) => { +>onError : Symbol(onError, Decl(reverseMappedIntersectionInference1.ts, 34, 15)) +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference1.ts, 35, 14)) + + errorArg; +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference1.ts, 35, 14)) + + }, + }, +}); + diff --git a/tests/baselines/reference/reverseMappedIntersectionInference1.types b/tests/baselines/reference/reverseMappedIntersectionInference1.types new file mode 100644 index 0000000000000..6e035116b03b3 --- /dev/null +++ b/tests/baselines/reference/reverseMappedIntersectionInference1.types @@ -0,0 +1,151 @@ +//// [tests/cases/compiler/reverseMappedIntersectionInference1.ts] //// + +=== reverseMappedIntersectionInference1.ts === +type Results = { +>Results : Results +> : ^^^^^^^^^^ + + [K in keyof T]: { + data: T[K]; +>data : T[K] +> : ^^^^ + + onSuccess: (data: T[K]) => void; +>onSuccess : (data: T[K]) => void +> : ^ ^^ ^^^^^ +>data : T[K] +> : ^^^^ + + }; +}; + +type Errors = { +>Errors : Errors +> : ^^^^^^^^^ + + [K in keyof E]: { + error: E[K]; +>error : E[K] +> : ^^^^ + + onError: (data: E[K]) => void; +>onError : (data: E[K]) => void +> : ^ ^^ ^^^^^ +>data : E[K] +> : ^^^^ + + }; +}; + +declare function withKeyedObj( +>withKeyedObj : (arg: Results & Errors) => [T, E] +> : ^ ^^ ^^ ^^ ^^^^^ + + arg: Results & Errors +>arg : Results & Errors +> : ^^^^^^^^^^^^^^^^^^^^^^ + +): [T, E]; + +const res = withKeyedObj({ +>res : [{ a: string; b: boolean; }, { a: number; b: number; }] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>withKeyedObj({ a: { data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, }, b: { data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, },}) : [{ a: string; b: boolean; }, { a: number; b: number; }] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>withKeyedObj : (arg: Results & Errors) => [T, E] +> : ^ ^^ ^^ ^^ ^^^^^ +>{ a: { data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, }, b: { data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, },} : { a: { data: string; onSuccess: (dataArg: string) => void; error: number; onError: (errorArg: number) => void; }; b: { data: true; onSuccess: (dataArg: boolean) => void; error: number; onError: (errorArg: number) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ + + a: { +>a : { data: string; onSuccess: (dataArg: string) => void; error: number; onError: (errorArg: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>{ data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, } : { data: string; onSuccess: (dataArg: string) => void; error: number; onError: (errorArg: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + data: "foo", +>data : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + onSuccess: (dataArg) => { +>onSuccess : (dataArg: string) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(dataArg) => { dataArg; } : (dataArg: string) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>dataArg : string +> : ^^^^^^ + + dataArg; +>dataArg : string +> : ^^^^^^ + + }, + error: 404, +>error : number +> : ^^^^^^ +>404 : 404 +> : ^^^ + + onError: (errorArg) => { +>onError : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(errorArg) => { errorArg; } : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>errorArg : number +> : ^^^^^^ + + errorArg; +>errorArg : number +> : ^^^^^^ + + }, + }, + b: { +>b : { data: true; onSuccess: (dataArg: boolean) => void; error: number; onError: (errorArg: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>{ data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, } : { data: true; onSuccess: (dataArg: boolean) => void; error: number; onError: (errorArg: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + data: true, +>data : true +> : ^^^^ +>true : true +> : ^^^^ + + onSuccess: (dataArg) => { +>onSuccess : (dataArg: boolean) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>(dataArg) => { dataArg; } : (dataArg: boolean) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>dataArg : boolean +> : ^^^^^^^ + + dataArg; +>dataArg : boolean +> : ^^^^^^^ + + }, + error: 500, +>error : number +> : ^^^^^^ +>500 : 500 +> : ^^^ + + onError: (errorArg) => { +>onError : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(errorArg) => { errorArg; } : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>errorArg : number +> : ^^^^^^ + + errorArg; +>errorArg : number +> : ^^^^^^ + + }, + }, +}); + diff --git a/tests/baselines/reference/reverseMappedIntersectionInference2.symbols b/tests/baselines/reference/reverseMappedIntersectionInference2.symbols new file mode 100644 index 0000000000000..18e65a100da78 --- /dev/null +++ b/tests/baselines/reference/reverseMappedIntersectionInference2.symbols @@ -0,0 +1,118 @@ +//// [tests/cases/compiler/reverseMappedIntersectionInference2.ts] //// + +=== reverseMappedIntersectionInference2.ts === +type Results = { +>Results : Symbol(Results, Decl(reverseMappedIntersectionInference2.ts, 0, 0)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference2.ts, 0, 13)) + + [K in keyof T]: { +>K : Symbol(K, Decl(reverseMappedIntersectionInference2.ts, 1, 3)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference2.ts, 0, 13)) + + data: T[K]; +>data : Symbol(data, Decl(reverseMappedIntersectionInference2.ts, 1, 19)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference2.ts, 0, 13)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference2.ts, 1, 3)) + + onSuccess: (data: T[K]) => void; +>onSuccess : Symbol(onSuccess, Decl(reverseMappedIntersectionInference2.ts, 2, 15)) +>data : Symbol(data, Decl(reverseMappedIntersectionInference2.ts, 3, 16)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference2.ts, 0, 13)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference2.ts, 1, 3)) + + }; +}; + +type Errors = { +>Errors : Symbol(Errors, Decl(reverseMappedIntersectionInference2.ts, 5, 2)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference2.ts, 7, 12)) + + [K in keyof E]: { +>K : Symbol(K, Decl(reverseMappedIntersectionInference2.ts, 8, 3)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference2.ts, 7, 12)) + + error: E[K]; +>error : Symbol(error, Decl(reverseMappedIntersectionInference2.ts, 8, 19)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference2.ts, 7, 12)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference2.ts, 8, 3)) + + onError: (data: E[K]) => void; +>onError : Symbol(onError, Decl(reverseMappedIntersectionInference2.ts, 9, 16)) +>data : Symbol(data, Decl(reverseMappedIntersectionInference2.ts, 10, 14)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference2.ts, 7, 12)) +>K : Symbol(K, Decl(reverseMappedIntersectionInference2.ts, 8, 3)) + + }; +}; + +declare function withTupleLike( +>withTupleLike : Symbol(withTupleLike, Decl(reverseMappedIntersectionInference2.ts, 12, 2)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference2.ts, 14, 31)) +>0 : Symbol(0, Decl(reverseMappedIntersectionInference2.ts, 14, 42)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference2.ts, 14, 56)) +>0 : Symbol(0, Decl(reverseMappedIntersectionInference2.ts, 14, 68)) + + arg: Results & Errors +>arg : Symbol(arg, Decl(reverseMappedIntersectionInference2.ts, 14, 83)) +>Results : Symbol(Results, Decl(reverseMappedIntersectionInference2.ts, 0, 0)) +>T : Symbol(T, Decl(reverseMappedIntersectionInference2.ts, 14, 31)) +>Errors : Symbol(Errors, Decl(reverseMappedIntersectionInference2.ts, 5, 2)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference2.ts, 14, 56)) + +): [T, E]; +>T : Symbol(T, Decl(reverseMappedIntersectionInference2.ts, 14, 31)) +>E : Symbol(E, Decl(reverseMappedIntersectionInference2.ts, 14, 56)) + +const res = withTupleLike([ +>res : Symbol(res, Decl(reverseMappedIntersectionInference2.ts, 18, 5)) +>withTupleLike : Symbol(withTupleLike, Decl(reverseMappedIntersectionInference2.ts, 12, 2)) + { + data: "foo", +>data : Symbol(data, Decl(reverseMappedIntersectionInference2.ts, 19, 3)) + + onSuccess: (dataArg) => { +>onSuccess : Symbol(onSuccess, Decl(reverseMappedIntersectionInference2.ts, 20, 16)) +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference2.ts, 21, 16)) + + dataArg; +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference2.ts, 21, 16)) + + }, + error: 404, +>error : Symbol(error, Decl(reverseMappedIntersectionInference2.ts, 23, 6)) + + onError: (errorArg) => { +>onError : Symbol(onError, Decl(reverseMappedIntersectionInference2.ts, 24, 15)) +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference2.ts, 25, 14)) + + errorArg; +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference2.ts, 25, 14)) + + }, + }, + { + data: true, +>data : Symbol(data, Decl(reverseMappedIntersectionInference2.ts, 29, 3)) + + onSuccess: (dataArg) => { +>onSuccess : Symbol(onSuccess, Decl(reverseMappedIntersectionInference2.ts, 30, 15)) +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference2.ts, 31, 16)) + + dataArg; +>dataArg : Symbol(dataArg, Decl(reverseMappedIntersectionInference2.ts, 31, 16)) + + }, + error: 500, +>error : Symbol(error, Decl(reverseMappedIntersectionInference2.ts, 33, 6)) + + onError: (errorArg) => { +>onError : Symbol(onError, Decl(reverseMappedIntersectionInference2.ts, 34, 15)) +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference2.ts, 35, 14)) + + errorArg; +>errorArg : Symbol(errorArg, Decl(reverseMappedIntersectionInference2.ts, 35, 14)) + + }, + }, +]); + diff --git a/tests/baselines/reference/reverseMappedIntersectionInference2.types b/tests/baselines/reference/reverseMappedIntersectionInference2.types new file mode 100644 index 0000000000000..4f5aa9e4d7d8d --- /dev/null +++ b/tests/baselines/reference/reverseMappedIntersectionInference2.types @@ -0,0 +1,150 @@ +//// [tests/cases/compiler/reverseMappedIntersectionInference2.ts] //// + +=== reverseMappedIntersectionInference2.ts === +type Results = { +>Results : Results +> : ^^^^^^^^^^ + + [K in keyof T]: { + data: T[K]; +>data : T[K] +> : ^^^^ + + onSuccess: (data: T[K]) => void; +>onSuccess : (data: T[K]) => void +> : ^ ^^ ^^^^^ +>data : T[K] +> : ^^^^ + + }; +}; + +type Errors = { +>Errors : Errors +> : ^^^^^^^^^ + + [K in keyof E]: { + error: E[K]; +>error : E[K] +> : ^^^^ + + onError: (data: E[K]) => void; +>onError : (data: E[K]) => void +> : ^ ^^ ^^^^^ +>data : E[K] +> : ^^^^ + + }; +}; + +declare function withTupleLike( +>withTupleLike : (arg: Results & Errors) => [T, E] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>0 : unknown +> : ^^^^^^^ +>0 : unknown +> : ^^^^^^^ + + arg: Results & Errors +>arg : Results & Errors +> : ^^^^^^^^^^^^^^^^^^^^^^ + +): [T, E]; + +const res = withTupleLike([ +>res : [[string, boolean], [number, number]] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>withTupleLike([ { data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, }, { data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, },]) : [[string, boolean], [number, number]] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>withTupleLike : (arg: Results & Errors) => [T, E] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>[ { data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, }, { data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, },] : [{ data: string; onSuccess: (dataArg: string) => void; error: number; onError: (errorArg: number) => void; }, { data: true; onSuccess: (dataArg: boolean) => void; error: number; onError: (errorArg: number) => void; }] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ + { +>{ data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, } : { data: string; onSuccess: (dataArg: string) => void; error: number; onError: (errorArg: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + data: "foo", +>data : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + onSuccess: (dataArg) => { +>onSuccess : (dataArg: string) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(dataArg) => { dataArg; } : (dataArg: string) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>dataArg : string +> : ^^^^^^ + + dataArg; +>dataArg : string +> : ^^^^^^ + + }, + error: 404, +>error : number +> : ^^^^^^ +>404 : 404 +> : ^^^ + + onError: (errorArg) => { +>onError : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(errorArg) => { errorArg; } : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>errorArg : number +> : ^^^^^^ + + errorArg; +>errorArg : number +> : ^^^^^^ + + }, + }, + { +>{ data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, } : { data: true; onSuccess: (dataArg: boolean) => void; error: number; onError: (errorArg: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + data: true, +>data : true +> : ^^^^ +>true : true +> : ^^^^ + + onSuccess: (dataArg) => { +>onSuccess : (dataArg: boolean) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>(dataArg) => { dataArg; } : (dataArg: boolean) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>dataArg : boolean +> : ^^^^^^^ + + dataArg; +>dataArg : boolean +> : ^^^^^^^ + + }, + error: 500, +>error : number +> : ^^^^^^ +>500 : 500 +> : ^^^ + + onError: (errorArg) => { +>onError : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(errorArg) => { errorArg; } : (errorArg: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>errorArg : number +> : ^^^^^^ + + errorArg; +>errorArg : number +> : ^^^^^^ + + }, + }, +]); + diff --git a/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts b/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts index 824a6d554344c..9b540f97206fd 100644 --- a/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts +++ b/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts @@ -31,3 +31,15 @@ f2( bar: (value, key) => {}, }, ); + +f2( + { + foo: 0, + bar: "", + }, + { + foo: (value, key) => { + // implicit `any`s + }, + }, +); diff --git a/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts new file mode 100644 index 0000000000000..9e0d3bc984031 --- /dev/null +++ b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix1.ts @@ -0,0 +1,38 @@ +// @strict: true +// @noEmit: true + +type ComponentType

= (p: P) => any; +type ComponentProps = C extends ComponentType ? P : never; + +type Attrs> = A; + +interface StyledFunction< + C extends ComponentType, + O extends object = {}, + A extends keyof any = never, +> { + attrs< + U, + NewA extends Partial & U> & { + [others: string]: any; + } = {}, + >( + attrs: Attrs & U, NewA>, + ): StyledFunction; +} + +interface StyledInterface { + >(component: C): StyledFunction; +} + +declare const styled: StyledInterface; + +interface BaseProps { + as?: "select" | "input"; +} + +declare const Flex: (props: BaseProps) => null; + +export const StyledSelect = styled(Flex).attrs({ + as: "select", +}); diff --git a/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts new file mode 100644 index 0000000000000..efa68a4854663 --- /dev/null +++ b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix2.ts @@ -0,0 +1,38 @@ +// @strict: true +// @noEmit: true + +type IntrinsicElements = { + a: { + href?: string; + }; + div: { + dir?: string; + }; +}; + +type Component = (props: Props) => unknown; + +interface NestedMDXComponents { + [key: string]: Component; +} + +type MDXComponents = NestedMDXComponents & { + [Key in keyof IntrinsicElements]?: Component; +}; + +export interface MDXProps { + components?: MDXComponents; +} + +declare function MyMDXComponent(props: MDXProps): null; + +MyMDXComponent({ + components: { + a(props) { + return null; + }, + div(props) { + return null; + }, + }, +}); diff --git a/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts new file mode 100644 index 0000000000000..42113a86f5775 --- /dev/null +++ b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts @@ -0,0 +1,31 @@ +// @strict: true +// @noEmit: true + +type TypeMap = { + str: "a" | "b" | "c"; + num: 1 | 2 | 3; +}; + +declare function test1< + T extends { [K in keyof TypeMap]: TypeMap[K][] } & { [k: string]: any[] }, +>(arg: T): T; + +const result = test1({ + num: [1, 2], + str: ["a", "b"], + bool: [true, false], +}); + +declare function test2(a: { type: "foo" | "bar" } & { type: any }): void; + +test2({ type: "foo" }); + +// https://github.com/microsoft/TypeScript/issues/59473 + +const x: { ml: any } & { ml: 'edge' } = { ml: 'edge' }; +const a: [any] & [1] = [1]; +const b: any[] & 1[] = [1, 1]; +const c: { a: any } & { a: 1 } = { a: 1 }; +const d: (() => { a: 1 }) & (() => { a: any }) = () => ({ + a: 1, +}); diff --git a/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts new file mode 100644 index 0000000000000..c43a322a29620 --- /dev/null +++ b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix4.ts @@ -0,0 +1,52 @@ +// @strict: true +// @noEmit: true + +declare function test1( + arg: { a: (arg: number) => void } & { [k: string]: (arg: any) => void }, +): unknown; + +test1({ + a: (arg) => {}, + b: (arg) => {}, +}); + +declare function test2( + arg: { a: (arg: { foo: string }) => void } & { + [k: string]: (arg: { foo: any }) => void; + }, +): unknown; + +test2({ + a: (arg) => {}, + b: (arg) => {}, +}); + +declare function test3( + arg: { a: () => "foo" } & { + [k: string]: () => any; + }, +): unknown; + +test3({ + a: () => "foo", + b: () => "bar", +}); + +test3({ + a: () => "bar", +}); + +declare function test4( + arg: { a: () => { prop: "foo" } } & { + [k: string]: () => { prop: any }; + }, +): unknown; + +test4({ + a: () => ({ prop: "foo" }), + b: () => ({ prop: "bar" }), +}); + +test4({ + a: () => ({ prop: "bar" }), +}); diff --git a/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts new file mode 100644 index 0000000000000..942d7e0a04925 --- /dev/null +++ b/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix5.ts @@ -0,0 +1,59 @@ +// @strict: true +// @noEmit: true + +type ComputedGetter = (oldValue?: T) => T; +type ComputedOptions = Record>; + +type ExtractComputedReturns = { + [key in keyof T]: T[key] extends (...args: any[]) => infer TReturn + ? TReturn + : never; +}; + +interface ComponentOptionsBase { + data?: D; + computed?: C; +} + +type ComponentPublicInstance = D & + ExtractComputedReturns; + +type ComponentOptions< + D = any, + C extends ComputedOptions = any, +> = ComponentOptionsBase & ThisType>; + +interface App { + mixin(mixin: ComponentOptions): this; +} + +interface InjectionKey extends Symbol {} + +interface Ref { + _v: T; +} + +declare function reactive(target: T): Ref; + +interface ThemeInstance { + readonly name: Readonly>; +} + +declare const ThemeSymbol: InjectionKey; + +declare function inject( + this: ComponentPublicInstance, + key: InjectionKey | string, +): any; + +declare const app: App; +app.mixin({ + computed: { + $vuetify() { + // this is meant to be `any` here + return reactive({ + theme: inject.call(this, ThemeSymbol), + }); + }, + }, +}); diff --git a/tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts b/tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts new file mode 100644 index 0000000000000..661595ea48862 --- /dev/null +++ b/tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts @@ -0,0 +1,147 @@ +// @strict: true +// @noEmit: true + +// repro from #48812 + +type Action = (ev: TEvent) => void; + +interface MachineConfig { + schema: { + events: TEvent; + }; + on?: { + [K in TEvent["type"]]?: Action; + } & { + "*"?: Action; + }; +} + +declare function createMachine( + config: MachineConfig +): void; + +createMachine({ + schema: { + events: {} as { type: "FOO" } | { type: "BAR" }, + }, + on: { + FOO: (ev) => { + ev.type; // should be 'FOO' + }, + }, +}); + +createMachine({ + schema: { + events: {} as { type: "FOO" } | { type: "BAR" }, + }, + on: { + "*": (ev) => { + ev.type; // should be 'FOO' | 'BAR' + }, + }, +}); + +interface MachineConfig2 { + schema: { + events: TEvent; + }; + on?: { + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; + } & { + "*"?: Action; + }; +} + +declare function createMachine2( + config: MachineConfig2 +): void; + +createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + FOO: (ev) => { + ev.type; // should be 'FOO' + }, + }, +}); + +createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + "*": (ev) => { + ev.type; // should be 'FOO' | 'bar' + }, + }, +}); + +createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + bar: (ev) => { + ev // any + }, + }, +}); + +// repro from #49307#issuecomment-1143103607 + +declare function createSlice( + reducers: { [K: string]: (state: string) => void } & { + [K in keyof T]: object; + } +): void; + +createSlice({ + f(a) {}, +}); + +// repro from #49307#issuecomment-1196014488 + +type Validate = T & { [K in keyof T]: object } +declare function f any>>(s: S, x: Validate): void; + +f(0, { + foo: s => s + 1, +}) + +// repro from 49307#issuecomment-1195858950 + +type SliceCaseReducers = Record State | void>; + +type ValidateSliceCaseReducers> = ACR & { + [T in keyof ACR]: ACR[T] extends { + reducer(s: S, action?: infer A): any; + } + ? { + prepare(...a: never[]): Omit; + } + : {}; +}; + +declare function createSlice< + State, + CaseReducers extends SliceCaseReducers +>(options: { + initialState: State | (() => State); + reducers: ValidateSliceCaseReducers; +}): void; + +export const clientSlice = createSlice({ + initialState: { + username: "", + isLoggedIn: false, + userId: "", + avatar: "", + }, + reducers: { + onClientUserChanged(state) {}, + }, +}); + diff --git a/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts b/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts new file mode 100644 index 0000000000000..6851ed2455b90 --- /dev/null +++ b/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType1.ts @@ -0,0 +1,47 @@ +// @strict: true +// @noEmit: true + +type IntrinsicElements = { + div: { + onChange: (ev: Event) => void; + }; + span: { + onChange: (ev: Event) => void; + }; +}; + +type ElementType = keyof IntrinsicElements; + +let DEFAULT_TABS_TAG = "div" as const; + +type Props = Omit< + IntrinsicElements[TTag], + keyof Overrides +> & + Overrides; + +type TabGroupProps = Props< + TTag, + { + defaultIndex?: number; + onChange?: (index: number) => void; + selectedIndex?: number; + vertical?: boolean; + manual?: boolean; + } +>; + +interface _internal_ComponentTabGroup { + ( + props: TabGroupProps, + ): null; +} + +declare let TabGroup: _internal_ComponentTabGroup; + +TabGroup({ + defaultIndex: 0, + onChange: (index) => { + const i: number = index; + }, +}); diff --git a/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts b/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts new file mode 100644 index 0000000000000..58f38124556c3 --- /dev/null +++ b/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType2.ts @@ -0,0 +1,28 @@ +// @strict: true +// @noEmit: true + +type Tags = P extends Record ? X : never; + +declare const typeTags: () => < + P extends { + readonly [Tag in Tags<"_tag", I> & string]: ( + _: Extract, + ) => any; + } & { readonly [Tag in Exclude>]: never }, +>( + fields: P, +) => unknown; + +type Value = { _tag: "A"; a: number } | { _tag: "B"; b: number }; +const matcher = typeTags(); + +matcher({ + A: (_) => _.a, + B: (_) => "fail", +}); + +matcher({ + A: (_) => _.a, + B: (_) => "fail", + C: (_) => "fail", +}); diff --git a/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts b/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts new file mode 100644 index 0000000000000..3eb0fa4e4db33 --- /dev/null +++ b/tests/cases/compiler/contextualTypesNegatedTypeLikeConstraintInGenericMappedType3.ts @@ -0,0 +1,49 @@ +// @strict: true +// @noEmit: true + +type MappedOmit = { [P in keyof T as Exclude]: T[P]; } + +type IntrinsicElements = { + div: { + onChange: (ev: Event) => void; + }; + span: { + onChange: (ev: Event) => void; + }; +}; + +type ElementType = keyof IntrinsicElements; + +let DEFAULT_TABS_TAG = "div" as const; + +type Props = MappedOmit< + IntrinsicElements[TTag], + keyof Overrides +> & + Overrides; + +type TabGroupProps = Props< + TTag, + { + defaultIndex?: number; + onChange?: (index: number) => void; + selectedIndex?: number; + vertical?: boolean; + manual?: boolean; + } +>; + +interface _internal_ComponentTabGroup { + ( + props: TabGroupProps, + ): null; +} + +declare let TabGroup: _internal_ComponentTabGroup; + +TabGroup({ + defaultIndex: 0, + onChange: (index) => { + const i: number = index; + }, +}); diff --git a/tests/cases/compiler/contextuallyTypedJsxAttribute2.tsx b/tests/cases/compiler/contextuallyTypedJsxAttribute2.tsx new file mode 100644 index 0000000000000..003a44b6d8287 --- /dev/null +++ b/tests/cases/compiler/contextuallyTypedJsxAttribute2.tsx @@ -0,0 +1,28 @@ +// @strict: true +// @jsx: react +// @esModuleInterop: true +// @noEmit: true + +/// + +import React from "react"; +import { ComponentPropsWithRef, ElementType } from "react"; + +function UnwrappedLink( + props: Omit, "as">, +) { + return ; +} + + {}} />; + +function UnwrappedLink2( + props: Omit, "as"> & { + as?: T; + }, +) { + return ; +} + + {}} />; + {}} />; diff --git a/tests/cases/compiler/reverseMappedIntersectionInference1.ts b/tests/cases/compiler/reverseMappedIntersectionInference1.ts new file mode 100644 index 0000000000000..27b6889eb7c54 --- /dev/null +++ b/tests/cases/compiler/reverseMappedIntersectionInference1.ts @@ -0,0 +1,43 @@ +// @strict: true +// @noEmit: true + +type Results = { + [K in keyof T]: { + data: T[K]; + onSuccess: (data: T[K]) => void; + }; +}; + +type Errors = { + [K in keyof E]: { + error: E[K]; + onError: (data: E[K]) => void; + }; +}; + +declare function withKeyedObj( + arg: Results & Errors +): [T, E]; + +const res = withKeyedObj({ + a: { + data: "foo", + onSuccess: (dataArg) => { + dataArg; + }, + error: 404, + onError: (errorArg) => { + errorArg; + }, + }, + b: { + data: true, + onSuccess: (dataArg) => { + dataArg; + }, + error: 500, + onError: (errorArg) => { + errorArg; + }, + }, +}); diff --git a/tests/cases/compiler/reverseMappedIntersectionInference2.ts b/tests/cases/compiler/reverseMappedIntersectionInference2.ts new file mode 100644 index 0000000000000..107050d26acbe --- /dev/null +++ b/tests/cases/compiler/reverseMappedIntersectionInference2.ts @@ -0,0 +1,43 @@ +// @strict: true +// @noEmit: true + +type Results = { + [K in keyof T]: { + data: T[K]; + onSuccess: (data: T[K]) => void; + }; +}; + +type Errors = { + [K in keyof E]: { + error: E[K]; + onError: (data: E[K]) => void; + }; +}; + +declare function withTupleLike( + arg: Results & Errors +): [T, E]; + +const res = withTupleLike([ + { + data: "foo", + onSuccess: (dataArg) => { + dataArg; + }, + error: 404, + onError: (errorArg) => { + errorArg; + }, + }, + { + data: true, + onSuccess: (dataArg) => { + dataArg; + }, + error: 500, + onError: (errorArg) => { + errorArg; + }, + }, +]);