Skip to content

Suggest Did you mean 'typeof Foo' when using value Foo as a type #28975

Closed

Description

@mohsen1
type Foo<T> = {}

const Something = []

type FooSomething = Foo<Something>
//                      ^
//                      Can not find name "Something"               

Instead, suggest that Something is in the value space and user possibly meant typeof Something.

Search Terms

Error messages, type space, generics

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Activity

  1. changed the title [-]Suggest `Did you mean 'typeof Foo'` when using value Foo as a type argument[/-] [+]Suggest `Did you mean 'typeof Foo'` when using value Foo as a type[/+] on Dec 12, 2018
  2. DanielRosenwasser commented on Dec 12, 2018

    @DanielRosenwasser
    Member

    I think this is more general than a type argument; probably as a type in general.

  3. DanielRosenwasser commented on Dec 12, 2018

    @DanielRosenwasser
    Member

    Wesley Wigham (@weswigham) has some concerns regarding things like the following

    type FooInstance = { }
    
    function Foo(): FooInstance {
    
    }
    
    // you probably don't want this to be corrected to 'typeof Foo'
    type FooAlias = Foo;
  4. s-lambert commented on Dec 12, 2018

    @s-lambert

    But that code doesn't seem to work, it won't compile because you do need typeof Foo to assign it to a type.

  5. mohsen1 commented on Dec 12, 2018

    @mohsen1
    ContributorAuthor

    Daniel Rosenwasser (@DanielRosenwasser) I think you meant class Foo {} that works in both type and value spaces

  6. cpplearner commented on Dec 12, 2018

    @cpplearner

    Perhaps it's more likely that InstanceType<typeof Foo> is intended?

  7. suhailsinghbains commented on Jan 5, 2019

    @suhailsinghbains

    Hi, Can I please work on this issue, I am new here

  8. jtbandes commented on Apr 5, 2020

    @jtbandes
    Contributor

    Andrew Casey (@amcasey) Should this issue be closed now as #37359 is merged? Looks like #32543 would have auto-closed this ticket but it was abandoned in favor of #37359.

  9. weswigham commented on Apr 5, 2020

    @weswigham
    Member

    Ah, yep.

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

    Domain: Error MessagesThe issue relates to error messagingExperience EnhancementNoncontroversial enhancementsFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions