Skip to content

Debugging feature: a zero key #76

@barona-mika-vilpas

Description

@barona-mika-vilpas

The problem is that unlike, say, C#, JS doesn’t have a way of customizing how an object is visualized in the debugger. So if you want to figure out what an object is exactly you have to rummage around in various properties or using the console.

A cool trick I’ve been using at work is to put a textual description of an object into the 0 key on that object (without a matching TS signature, it’s just for runtime). It has to be a value key, so usually I generate it in the constructor for immutable objects.

The 0 key is the first key that will be printed and shown by debuggers, so it lets developers immediately see what object they’re dealing with. The trick works on lots of different IDEs and debuggers. Here is an example from JetBrains:

image

The description that goes into this key would be the single line description.

This came up in the discussion in #64

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions