Skip to content

Sort out typescript support #37

@Download

Description

@Download

I would like ulog to have typescript support out of the box.

This has been requested multiple times:

Now is the time to do it as the library design for v2 has mostly stabilized now and the public signature for ulog is mostly clear.
There are some challenges to overcome though.

We have the complex situation that methods and properties are being added to ulog and all loggers dynamically at runtime through mods. E.g. in normal situations (using the default mods), two methods, get() and set(), will be added to ulog by the settings mod. In fact any mod that has an extends key will end up extending the ulog object itself. Looking at the source of the settings mod for example we see this:

module.exports = {
  extend: {
    settings: {},
    get: function() { /* ... */  },
    set: function() { /* ... */ },
  }
}

So this mod adds a settings property and methods get and set to ulog.

I have no idea how to model this with Typescript... Maybe mods could include their own typescript definitions? But I think we will find that it's not actually possible because Typescript AFAIK is a compile-time tool so cannot rely on run-time behavior.

So for now my idea is this:

We start simple and first make the base typescript definition that extends the one from anylogger and only adds the stuff that is added in core:

ulog.mods = []
ulog.use = function(mod) { /* ... */ }

Let's call this core.d.ts

We then make typescript definitions for all the standard entries that ulog offers:

  • ulog: The basic config you get when you require('ulog')
  • full: The config with all mods included you get when you require('ulog/full')
  • debug: A config designed to closely resemble debug
  • ... (not sure yet)

So we would get:

  • ulog.d.ts extends core.d.ts
  • full.d.ts extends ulog.d.ts
  • debug.d.ts extends ulog.d.ts
  • ...

I would love for someone that is experienced with Typescript to prepare a PR for this. This time, it will get merged, I promise you!

Here is a list of of people that have expressed an interest in adding typescript to ulog in the past:

I am hoping one of you finds the time to help out with this. I know you wanted this in the past, but the project (read: I) wasn't ready for it yet. Now, we are ready to add this, so grab your chance and get listed on the credits! 👍

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions