Repository navigation
suggest fix when using value as type argument - #32543
John Patterson (john-patterson) wants to merge 9 commits into
Conversation
|
So the original issue outline in the issue showed this: type Foo<T> = {}
const Something = []
type FooSomething = Foo<Something>
// ^
// Can not find name "Something" The error has since been updated to The validity of suggesting to use Wesley Wigham (@weswigham) What were your concrete concerns here? It wasn't clear from Daniel's comments |
|
Ryan Cavanaugh (@RyanCavanaugh) just that suggesting |
e1a208b to
95c822e
Compare
|
Wesley Wigham (@weswigham) I'm still a little unsure of what you mean. What I'm understanding as your argument is: it's more likely a user wants |
|
As a side-note, it might be useful (on this PR or some other) to add an actual code fix operation for to go along with this error message change. Any objections? |
|
John Patterson (@john-patterson) yep, that was my premise. Its probably not too important, it was just a scenario to think about while this was implemented. |
|
Sorry to have orphaned this PR. To be clear, the issue is now just changing this message:
To be something like:
I'll try to remember to gut the rest of this PR this weekend. |
This addresses issue microsoft#28975 (microsoft#28975). When providing a value as a type argument, we can suggest a more specific error message: "Did you mean to use typeof T?" adds error message WIP: Detect error WIP: progress updated tests janky implementation
95c822e to
ace16fb
Compare
This suggests 'typeof T' as a potential alternative when we give an error about using value T as a type.
|
Closing in favor of #37359. |
Fixes #28975.
As discussed in the body of the issue, this only makes a new suggestion when a value appears with as a type argument, like .
So, given the setup from #28975:
type Foo<T> = {}; const Something = [];,This generates the new "error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'?" error:
type SomeFoo = Foo<Something>;but a simple aliasing,
type SomeBar = Something;generates the old "error TS2749: 'Something' refers to a value, but is being used as a type here." error.
I couldn't figure out a cleaner way to write the
isIdentifierATypeArgumentfunction. Currently, I'm checking the failing node's grandparent to see if the current node is in that node'stypeArguments. This involves some casting and a findIndex, so if there's a better way to divine that with eithermeaningornode.kind, that would be preferrable.