I have:
type Foo = {n:number}
function test(f:Foo){}
When I type
test()
The popover shows "test(f: Foo): void". How can I let the popover shows "{n:number}".(I don't want to change the function definition.)
I have:
type Foo = {n:number}
function test(f:Foo){}
When I type
test()
The popover shows "test(f: Foo): void". How can I let the popover shows "{n:number}".(I don't want to change the function definition.)
Go to VSCode - Open User Settings (JSON) and paste in the following lines:
"typescript.inlayHints.enumMemberValues.enabled": true,
"typescript.inlayHints.functionLikeReturnTypes.enabled": true
"typescript.inlayHints.parameterNames.enabled": "all"
If you want intellisense to detect the internal workings of the type you should use a generic function to extend it
eg
type Foo = { n: number };
function test<Bar extends Foo>(f: Bar) {}
test({n: 0});
First, the way the test()
function is being called above is an error and doesn't satisfy the required type { n: number; }
if you made it conditionally undefined such as
function test<Bar extends Foo>(f?: Bar) {}
then calling test()
with no arguments would be okay
at any rate, extending the original type with a generic exposes the internal type workings on hover which I believe is what you're asking about
when I hover test({n:0})
using the following syntax
type Foo = { n: number };
function test<Bar extends Foo>(f: Bar) {}
test({n: 0});
typescript intellisense detects the following
function test<{
n: number;
}>(f: {
n: number;
}): void