Skip to content

Mapped tupples with generic constraintsΒ #55223

Closed
@npenin

Description

@npenin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions