Skip to content

No string completions in type arguments where constrained to string literal union #52898

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

Open
andrewbranch opened this issue Feb 21, 2023 · 4 comments
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Milestone

Comments

@andrewbranch
Copy link
Member

andrewbranch commented Feb 21, 2023

A friend of mine recently tried using JSX generics and it seems like the fix in #34958 did not work for them.

Here is an oversimplified code snippet that replicates the issue. We've tried this in two different machines and neither worked:

import * as React from "react"

type Variations = "hello" | "baaaaa" | "click"

const MyGeneric = <T extends Variations>({  }) => {
  return <div></div>
}

const Issue = () => {
  return <MyGeneric<"ctrl+space should bring up suggestions here">></MyGeneric>
}

Originally posted by @varemenos in #34110 (comment)

@andrewbranch andrewbranch added Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Domain: Completion Lists The issue relates to showing completion lists in an editor labels Feb 21, 2023
@andrewbranch andrewbranch added this to the Backlog milestone Feb 21, 2023
@andrewbranch andrewbranch added the Bug A bug in TypeScript label Feb 21, 2023
@Andarist
Copy link
Contributor

For the record - this isn't exclusive to JSX. It doesn't work with regular call expressions either (TS playground):

import * as React from "react"

type Variations = "hello" | "baaaaa" | "click"

const MyGeneric = <T extends Variations>({  }) => {
  return <div></div>
}

MyGeneric<"ctrl+space should bring up suggestions here">({})

@andrewbranch andrewbranch changed the title No string completions in JSX element type arguments No string completions in type arguments where constrained to string literal union Feb 22, 2023
@Andarist
Copy link
Contributor

Andarist commented Feb 22, 2023

And it's not even about string completions:

declare function test<T extends { type: 'a' | 'b' }>(): void

test<{ type: /*1*/ }>()

test<{ type: '/*2*/' }>()

test<{ /*3*/ }>()

I didn't do further research right now to confirm this but I'm under impression that completions just don't work in type arguments.

@andrewbranch
Copy link
Member Author

When I was looking for duplicates, I saw #43526, so I assumed that some support is implemented and there are just big gaps.

@kronodeus
Copy link

kronodeus commented Nov 7, 2023

Here is an even more simplified example that demonstrates that functions get no completions at all for type arguments while type references do:

type OneOrTwo = "one" | "two"

// Completions do not work for functions
declare function MyFunction<T extends OneOrTwo>(): T
MyFunction<'no completions here'>()

// Completions DO work for type references
type MyType<T extends OneOrTwo> = T
MyType<'completions here'>

I can't think of a reason why completion requests for type arguments can't be routed down the same code path for functions as they are for type references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants