question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use function type shorthands when displaying signature help

See original GitHub issue

From @unional on April 14, 2016 23:32

image I would be great if when tape((<cursor>)) it would be able to drill in the tape.TestCase and show the signature of the callback. 🌷

This is probably on tsc, but let’s start here. 😄

Copied from original issue: Microsoft/vscode#5284

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielRosenwassercommented, Aug 4, 2016

Sure thing @unional. All objects have a set of members. These aren’t the same things as properties. A property is a type of member, but members also include:

  • call signatures
  • construct signatures
  • index signatures

The thing that allows a type to be callable is a call signature. You might already be familiar with call signatures if you’ve thought about overloads.

Here is an example of a type with a single call signature:

interface Foo {
    (hello: string, world: number): void;
}

If I have something of type Foo, I can call it with a string and number.

let f: Foo = /* ... */;

f("hello!", 100);

You can also have multiple call signatures.

interface Foo {
    (hello: string, world: number): void;
    (hello: string): void;
}

If Foo was declared like that, you could have also called f like so:

f("hello!");

We have two different shorter ways of writing things with call signatures. One place is method members.

If you have something like

interface Bar {
    m(): void;
}

Here, Bar is actually equivalent to

interface Bar {
    m: {
        (): void;
    }
}

Meaning that Bar has a property named m, which has a single call signature.

Another short-hand that we use is arrow function types. These are just objects with a single call signature.

In other words, if you’ve ever seen (x: number) => void, that’s actually just an easier way of writing the type { (x: number): void }.

Which is why I think that if you have an interface type with no members apart from a single call signature, we should consider showing the arrow function notation.


For more about call signatures, you can check out the language spec too: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3.9.2

0reactions
unionalcommented, Aug 4, 2016

@DanielRosenwasser many thanks! Great examples. Especially that Bar and the arrow function one. Didn’t know function signature is expanded to a property with single call signature (in this case). It does make a lot of sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Read Function Type Signatures - YouTube
For functional programming beginners: How to read type signatures. Also known as: What do all those silly characters mean?Being able to read ...
Read more >
typing — Support for type hints — Python 3.11.1 documentation
Using that shorthand is recommended. Details: The arguments must be types and there must be at least one.
Read more >
How types work with functions · F# for Fun and Profit - swlaschin
We've seen that the arrow notation " -> " is used to show the domain and range. So that a function signature always...
Read more >
Viewing method parameter information | WebStorm ... - JetBrains
To have a complete method or function signature shown instead of a list of required types, select the Show full method signatures checkbox...
Read more >
Use a screen reader to add a signature in Outlook
Type a name for the signature. When you're done, press Enter. Tip: Give signatures descriptive names, such as "business closing." A good name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found