Skip to content

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

Open
@andrewbranch

Description

@andrewbranch
Member

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)

Activity

added
Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".
Domain: Completion ListsThe issue relates to showing completion lists in an editor
on Feb 21, 2023
added this to the Backlog milestone on Feb 21, 2023
Andarist

Andarist commented on Feb 21, 2023

@Andarist
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">({})
changed the title [-]No string completions in JSX element type arguments[/-] [+]No string completions in type arguments where constrained to string literal union[/+] on Feb 22, 2023
Andarist

Andarist commented on Feb 22, 2023

@Andarist
Contributor

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

andrewbranch commented on Feb 22, 2023

@andrewbranch
MemberAuthor

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

kronodeus

kronodeus commented on Nov 7, 2023

@kronodeus

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.

mkantor

mkantor commented on May 23, 2025

@mkantor
Contributor

I looked into this briefly while working on #61758. I noticed that having the cursor within a string literal type argument of an expression is a "known invalid completion location" according to getCompletionData in completions.ts. A fix for this issue would probably have to address that before anything else.

mkantor

mkantor commented on May 23, 2025

@mkantor
Contributor

@Andarist

And it's not even about string completions

There's a constellation of related issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editorEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mkantor@andrewbranch@Andarist@kronodeus

        Issue actions

          No string completions in type arguments where constrained to string literal union · Issue #52898 · microsoft/TypeScript