Skip to content

Can't remap tuple keys to object keys in mapped types #55762

Description

🔎 Search Terms

mapped tuple, mapped types

🕗 Version & Regression Information

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

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2#code/CYUwxgNghgTiAEkoGdnwCLgPahgHgBUA+eAbwCh4r5QwcQAKWGKATwCEBXAM25BgBc8AIIwWHHnxgBKIQQDc5AL7lyAF1YAHBADUoETiAJaQAeW6F4IAB5qQAO2BpMdXHij3WREgF54BK1sHJwxsNwBLeyl4ACUSAH5Y+CF7EAA3fkV1E3gAZTUYTjA1TGQwGHDNNSwYeD8YkChgLHsIVlFxPDgmlrb4AG0AaxBWIWQCyIBzABp4DW0hF3p8Dy8AXSIs+YR8wuLjbQAxGrxS8srq2ps7RzRdopKQMoqqmt8ySmp+gGl4SPgGMNWFhuKFnhcatJ4AAyeD2TgAWwARvx4CgwedXjAfmt+gAGNZrIR6AxGEzmU5PTGXHH9ACMG0USiySFQeQKDyWbjo9nGGJel0CNxC92KZwFbyFwWcYX4eFFagOIGO+HFEJg3g+1EQLXGe0uDFA4KxiypEpkWu11GQnG0MAY0kU2pUKnItGgcB1vLUfwAzAAmLn8U2uOXw5H8TZu8AehA8vnhABsABYg4JQqH8EjwpNImoo+R4z69ZzZbU-KkAO7s-Vphj9T5UfoAIigzdm4QDabW00bA2bSPbfxT3d7a0dqiL8BLxTq045YrLADpaPQGFWRGI2FxePwGHS8XjpBPC7qfWkUoiUeX5-ql1BFEA

💻 Code

declareclassDecoder<T>{decode(arrayBuffer: ArrayBuffer): T;}typeValueTypeOf<TextendsDecoder<any>>=TextendsDecoder<infer R> ? R : never;typeStructDescriptor=ReadonlyArray<readonly[key: string,type: Decoder<any>]>;typeStructTypeFor<DescriptorextendsStructDescriptor>={[Kin(keyofDescriptor)&numberasDescriptor[K][0]]: ValueTypeOf<Descriptor[K][1]>;};classStructDecoder<constDescriptorextendsStructDescriptor>extendsDecoder<StructTypeFor<Descriptor>>{constructor(descriptor: Descriptor){super();}}declareconsti32Decoder: Decoder<number>;declareconsti64Decoder: Decoder<bigint>;conststructDecoder=newStructDecoder([["a",i32Decoder],["b",i64Decoder],]);conststruct=structDecoder.decode(newArrayBuffer(100));// I expected this would work, but it does notconstv: number=struct.a;

🙁 Actual behavior

The type of struct.a has type number | bigint, however it should only have type number.

🙂 Expected behavior

struct.a should have type number (and similarly struct.b should have type bigint).

Additional information about the issue

This does work when using a record instead, however this isn't as useful as I want the descriptor to still be an array so I can iterate over it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions