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

Mapped tupples with generic constraints #55223

Closed
npenin opened this issue Aug 1, 2023 · 2 comments
Closed

Mapped tupples with generic constraints #55223

npenin opened this issue Aug 1, 2023 · 2 comments

Comments

@npenin
Copy link

npenin commented Aug 1, 2023

Bug Report

πŸ”Ž Search Terms

mapped tupples generic constraints

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

export interface wasmtype<T extends wasmtypeInstance<T>>
{
    new(initialOp: (number | bigint)[]): T;
    type: number;
}

export interface wasmtypeInstance<T extends wasmtypeInstance<T>>
{
    toOpCodes(): (number | bigint)[];
    type: wasmtype<T>
}

export type parameters<T extends wasmtypeInstance<any>[]> = T extends never[] ? never[] :
    T extends [infer T1] ? [T1['type']] :
    T extends [infer T1, infer T2] ? [T1, T2] :
    T extends [infer T1, infer T2, infer T3] ? [T1, T2, T3] :
    T extends [infer T1, infer T2, infer T3, infer T4] ? [T1, T2, T3, T4] :
    T extends [infer T1, infer T2, infer T3, infer T4, infer T5] ? [T1, T2, T3, T4, T5] :
    T extends [infer T1, infer T2, infer T3, infer T4, infer T5, infer T6] ? [T1, T2, T3, T4, T5, T6] :
    T extends [infer T1, infer T2, infer T3, infer T4, infer T5, infer T6, infer T7] ? [T1, T2, T3, T4, T5, T6, T7] :
    T
    ;

πŸ™ Actual behavior

The compiler complains that T1 is not a wasmtypeInstance.

πŸ™‚ Expected behavior

Since T1 extends wasmtypeInstance (based on the generic constraint), T1['type'] should be an allowed structure as well. Ideally, it would return wasmtype because of the inference, but at least a wasmtype as specified in the constraint is a must.

@npenin
Copy link
Author

npenin commented Aug 1, 2023

a somehow connected usecase would be if your replace parameters with the following definition:

export type parameters<T extends wasmtypeInstance<any>[]> = T extends never[] ? never[] :
    T extends [infer T1] ? T1 extends wasmtypeInstance<T1> ? [T1['type']] : never :
    T extends [infer T1, infer T2] ? [T1, T2] :
    T extends [infer T1, infer T2, infer T3] ? [T1, T2, T3] :
    T extends [infer T1, infer T2, infer T3, infer T4] ? [T1, T2, T3, T4] :
    T extends [infer T1, infer T2, infer T3, infer T4, infer T5] ? [T1, T2, T3, T4, T5] :
    T extends [infer T1, infer T2, infer T3, infer T4, infer T5, infer T6] ? [T1, T2, T3, T4, T5, T6] :
    T extends [infer T1, infer T2, infer T3, infer T4, infer T5, infer T6, infer T7] ? [T1, T2, T3, T4, T5, T6, T7] :
    T
    ;

in the condition on T1 , the compiler is complaining about T1 not being a wasmtypeInstance, while it is part of the condition I am trying to validate.

@MartinJohns
Copy link
Contributor

MartinJohns commented Aug 1, 2023

Duplicate of #51108. Used search terms: infer constraint conditional type

As a workaround you can do this: T extends [infer T1 extends wasmtypeInstance<any>]

@npenin npenin closed this as completed Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants