Skip to content

Conditional type doesn't work inside tuple #40067

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

Closed
ienzam opened this issue Aug 15, 2020 · 3 comments
Closed

Conditional type doesn't work inside tuple #40067

ienzam opened this issue Aug 15, 2020 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ienzam
Copy link

ienzam commented Aug 15, 2020

TypeScript Version: 4.1.0-dev.20200807

Search Terms: conditional type tuple

Code

type Tuple<T> = [T extends null ? T? : T];

Expected behavior:
Expected the definition to work as expected.

Actual behavior:
Got the following error:

JSDoc types can only be used inside documentation comments.

Playground Link: Playground Link

Related Issues: Did not find anything close.

@jack-williams
Copy link
Collaborator

As per #24897, outside of JSDoc the ? modifier is only valid for tuple elements, not arbitrary types. It does not make sense to say that a type can be omitted, only that an element can be omitted.

@ienzam
Copy link
Author

ienzam commented Aug 18, 2020

The above definition is inside a tuple, and one way to look at that is the element can be omitted or not.
But I guess that messes up in other ways like making sure all the other elements are optional too.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 3, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants