Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Argument of type ... is not assignable to parameter of type ... #29505

Closed
asfernandes opened this issue Jan 21, 2019 · 6 comments · Fixed by #30639
Closed

Regression: Argument of type ... is not assignable to parameter of type ... #29505

asfernandes opened this issue Jan 21, 2019 · 6 comments · Fixed by #30639
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@asfernandes
Copy link

This were working without error in TypeScript 3.0.1 but is not working on 3.2.4.

The select function is intended to accept only property names of type string in the last argument, but in 3.2.4 it does not accept any string.

It gives error: [ts] Argument of type '"value"' is not assignable to parameter of type 'XX extends XX ? "value" : never'. [2345]

export type FilterPropsByType<T, TT> = {
	[K in keyof T]: T[K] extends TT ? K : never
}[keyof T];

function select<
	T extends string | number,
	TList extends object,
	TValueProp extends FilterPropsByType<TList, T>
>(
	property: T, list: TList[], valueProp: TValueProp
)
{
	//
}

export function func<XX extends string>(x: XX, tipos: { value: XX }[]) {
	select(x, tipos, 'value');
}
@jack-williams
Copy link
Collaborator

jack-williams commented Jan 23, 2019

EDIT: Also, I would recommend changing the issue name for visibility. Something like:

Conditional type is deferred when check and extend types are identical and instantiable.

I think this is a bug, but I'm not 100%. This will probably need @weswigham or @ahejlsberg to answer definitively.

I think this is a bug because wrapping the conditional type in a 1-tuple fixes the error, but it shouldn't really make a difference because the conditional type was never distributive in the first place. This works:

export type FilterPropsByType<T, TT> = {
	[K in keyof T]: [T[K]] extends [TT] ? K : never
}[keyof T];

Specifically, the code is skipping past this check because both the check and extends type are instantiable.

// We attempt to resolve the conditional type only when the check and extends types are non-generic
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, TypeFlags.Instantiable | TypeFlags.GenericMappedType)) {
    if (inferredExtendsType.flags & TypeFlags.AnyOrUnknown) {
        return instantiateType(root.trueType, mapper);
    }

and then dropping down into deferral:

// Return a deferred type for a check that is neither definitely true nor definitely false
const erasedCheckType = getActualTypeVariable(checkType);
const result = <ConditionalType>createType(TypeFlags.Conditional);

Checking for identity before deferral does fix the issue, but I'm not sure it's the right thing to do:

if (isTypeIdenticalTo(checkType, extendsType)) {
    return instantiateType(root.trueType, combinedMapper || mapper);
}
// Return a deferred type for a check that is neither definitely true nor definitely false
// ….

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jan 23, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.4.0 milestone Jan 23, 2019
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Mar 13, 2019
@RyanCavanaugh
Copy link
Member

@weswigham tentatively tagging this as a bug because it is indeed a regression relative to 3.1

@asfernandes
Copy link
Author

This bug was target for 3.5.0 milestone but it's still present in 3.5.1. I just cannot update TypeScript since 3.0.1 in my project.

@weswigham weswigham added the Fix Available A PR has been opened for this issue label Jul 15, 2019
@asfernandes
Copy link
Author

I just tested 3.6.0-dev.20190720 and the bug is still present.

@weswigham
Copy link
Member

Fix Available means there's a PR with the fix open, but it has yet to be merged (for whatever reason) - the issue will be closed once the fix is merged.

@RyanCavanaugh
Copy link
Member

The linked PR is pretty wide-reaching so I'm slightly hesitant to call it a definitive fix for the issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
6 participants