Skip to content

Leading Rest element in tuples are kinda broken !?Β #61842

Closed
@benzaria

Description

@benzaria

πŸ”Ž Search Terms

Rest Element
Tuples
Leading Rest Element Tuple

πŸ•— Version & Regression Information

Nightly

⏯ Playground Link

PlayGround

πŸ’» Code

type T = [...string[], number, boolean, symbol];
type First = T[0];

πŸ™ Actual behavior

type T = [...string[], number, boolean, symbol];
type First = T[0];
//      ^? First = string | number | boolean | symbol

πŸ™‚ Expected behavior

type T = [...string[], number, boolean, symbol];
type First = T[0];
//      ^? First = string | number

Additional information about the issue

Is this a common thing it doesn't make sense, like T[0] can never be boolean or symbol am I missing something.
Although I can be used to create type guard to check for leading rest element in arrays.

type IsLeadingRestElement<T extends UnknownArray> = If<IsAny<T>, false,
	number extends T['length']
		? T[number] extends T[0]
			? true
			: false
		: false
>;

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