Why libraries exist, and how to choose one: popularity, maintenance, built-in types or @types
See what a library gives your program and what it costs, look inside a package to find its code and its description, and ask four questions before you install one: does it do the job, how many use it, is anyone looking after it, and where are its types.
Fundamentals
TypeScript
Why libraries exist, and how to choose one: popularity, maintenance, built-in types or `@types`. Read this lesson at .
Tested with TypeScript 7.x · Node.js LTS
Module 13 left TaskKit in good shape: its tasks live in a TaskStore,
and the rest is functions and plain objects. This module gives it
three new things: colours in the terminal, real commands with their
own help, and due dates. Take the dates. "Due in 3 days" sounds like
adding 3 to a number, until the 30th of a month, a February in a leap
year, or the night the clocks move by an hour. People have written
that code already, and millions of programs run it every day.
A recipe that needs bread does not start with growing wheat. You buy a
loaf, but you read the label first: who made it, when, and what is
inside. Packages are the same. By the end of this lesson you can open
any package's page on npmjs.com and decide whether it goes into
TaskKit, and you know how to find where its types are.
Why libraries exist
A library is a package of code written for other programs to call.
TaskKit already uses two: boxen draws its banner (lesson 9.2), and
pluralize says "1 task" and "2 tasks" (lesson 9.3). npm calls
everything it installs a package; a library is the kind your own code
imports and calls. A tool, such as TypeScript, is one you run.
What you get is code that someone wrote once and thousands of programs
use. When it has a bug, one of those programs usually finds it first,
and the fix reaches everyone with the next version. A date library has
met every short month and leap year long before your code would.
What it costs is trust. A library's code runs inside TaskKit, though
you never read it, and its authors decide what happens to it next: a
new version, a change that needs your code changed, or nothing ever
again. It also brings other packages with it: npm install boxen
added fourteen, not one. So every package is a decision, and this lesson is
how to make it. Keeping a package safe once it is installed is what
the next lesson is about.
What is inside a package
You already have a package you never asked for: boxen needs chalk,
a library that colours text in the terminal, so it is already in
node_modules. Go and look inside it. In the
taskkit folder, run these one at a time (on Windows, type
ls -Name for ls, as in lesson 1.2):
Press Next step to walk through them, or let it play:
ana — ~/projects/taskkit/node_modules/chalk/source
ana@mac taskkit % cdnode_modules/chalk
ana@mac chalk % ls
license package.json readme.md source
ana@mac chalk % cdsource
ana@mac source % ls
index.d.ts index.js utilities.js vendor
ana@mac source %
ana@mac taskkit % cdnode_modules/chalk
ana@mac chalk % ls
license package.json readme.md source
ana@mac chalk % cdsource
ana@mac source % ls
index.d.ts index.js utilities.js vendor
ana@mac source %
source
boxenboxen
chalkchalk
pluralizepluralize
licenselicense
package.jsonpackage.json
readme.mdreadme.md
sourcesource
index.d.tsindex.d.ts
index.jsindex.js
utilities.jsutilities.js
vendorvendor
Into the package. boxen uses chalk, so npm put it on the shelf too.
The label, package.json; a readme and a licence for you; source.
Into the folder that holds what the package does.
index.js is the code Node runs; index.d.ts (d for declaration), the
description.
chalk is already in TaskKit: boxen brought it in lesson 9.2
All 4 steps shown.Step 1 of 4: cd node_modules/chalk → /Users/ana/projects/taskkit/node_modules/chalkStep 2 of 4: ls → /Users/ana/projects/taskkit/node_modules/chalkStep 3 of 4: cd source → /Users/ana/projects/taskkit/node_modules/chalk/sourceStep 4 of 4: ls → /Users/ana/projects/taskkit/node_modules/chalk/source
All 4 steps shown.Step 1 of 4: cd node_modules/chalk → C:\Users\ana\projects\taskkit\node_modules\chalkStep 2 of 4: ls -Name → C:\Users\ana\projects\taskkit\node_modules\chalkStep 3 of 4: cd source → C:\Users\ana\projects\taskkit\node_modules\chalk\sourceStep 4 of 4: ls -Name → C:\Users\ana\projects\taskkit\node_modules\chalk\source
All 4 steps shown.
Most packages have the same parts, as lesson 9.3 found in boxen's
folder. The code is for Node, and the description, a .d.ts file, is
for TypeScript. A readme says what the package does and how to call
it, and a licence what you may do with it. package.json is the
label: the package's name, its version, the packages it needs, and
where the rest is. Open node_modules/chalk/package.json in VS Code
(Visual Studio Code, your editor); these are the lines that say where:
"exports" lists what the package hands to code that imports it. Its
"types" line names the description, which TypeScript reads, and
"default" the code, which Node runs. That "types" belongs to the
package: it is not the types setting in TaskKit's tsconfig.json
(lesson 9.4), which lists descriptions that nothing imports. Some
packages also write "types" at the top of package.json, and it
means the same.
pluralize's package.json has no "types" line at all. It brought no
description, which is why lesson 9.3 installed @types/pluralize,
whose own package.json says "types": "index.d.ts". Go back to
taskkit with cd ../../.., three folders up.
Four questions before you install
Before a package goes into TaskKit, open its page on npmjs.com and ask
four questions. Any one of them can stop it.
Does it do the job? The readme, the main part of the page, says
what the package does and shows how to call it.
Do many projects use it? Beside the readme (under it on a
phone), Weekly Downloads says how many times it was installed
last week.
Is anyone looking after it?Last publish says when its
newest version came out, and the readme may say what its authors
think of it now.
Where are its types? Built in, or from @types: the next
section. Nowhere at all means pass it over (lesson 9.3).
Here are the four questions asked of two date libraries that a search
for due dates turns up. Switch between them, and press Next step
to walk through each, or let it play:
The job: passes✓Does it do due dates?
Popular: passes✓How many use it each week?
Looked after: passes✓Last publish, and what the readme says
Types: passes✓Built in, or from @types?
npm install: reachedOnly what passed every question
date-fns passes every question; moment is stopped by its own
readme
All 9 steps shown.Step 1 of 9: The jobStep 2 of 9: The job: passesStep 3 of 9: PopularStep 4 of 9: Popular: passesStep 5 of 9: Looked afterStep 6 of 9: Looked after: passesStep 7 of 9: TypesStep 8 of 9: Types: passesStep 9 of 9: npm install
All 9 steps shown.
The job: passes✓Does it do due dates?
Popular: passes✓How many use it each week?
Looked after: stops here✕Last publish, and what the readme says
Types: never reachedBuilt in, or from @types?
npm install: never reachedOnly what passed every question
Looked after stops hereIts readme: a legacy project, now in maintenance mode
date-fns passes every question; moment is stopped by its own
readme
All 6 steps shown.Step 1 of 6: The jobStep 2 of 6: The job: passesStep 3 of 6: PopularStep 4 of 6: Popular: passesStep 5 of 6: Looked afterStep 6 of 6: Looked after: stops here. Its readme: a legacy project, now in maintenance mode
All 6 steps shown.
On the numbers the two look alike: on 25 October 2026, date-fns had
tens of millions of downloads a week and its last publish was 5 months
old; moment had tens of millions a week too, and its last publish was
a month old. Only moment's readme tells them apart. It calls moment "a
legacy project, now in maintenance mode": old, kept working for the
programs that already use it, and not built on any more. New features
are not accepted. Its authors still fix it for the projects that have
it, but for code you write today, that is a reason to pass it over.
So downloads tell you that many projects found a package worth using,
and that bugs in it get found fast. They do not tell you it is still
looked after: old projects keep downloading what they installed years
ago. Nor is an old Last publish always bad. pluralize was last
published in 2019, and TaskKit uses it happily: it does one small job,
English plurals, needs no other package, and has nothing left to
change. A package that has to keep up with Node, terminals or the
calendar needs new versions; a small, finished one may not.
Built in, or from @types
Lesson 9.3 answered the fourth question with the icon after a
package's name on npmjs.com, and warned that the icon is sometimes
wrong. Here is such a case. On chalk's page the icon is the white
DT, for DefinitelyTyped, the volunteers' project that writes
@types descriptions: "This package has TypeScript declarations
provided by @types/chalk" (declarations: the site's word for
descriptions, as in lesson 9.3). date-fns's page has it too.
Yet you have just seen chalk's own description, in
source/index.d.ts. npmjs.com does not always find a description
named inside "exports", and here it points at an @types package
that is an empty stub: a package with no description in it. npm
marks that stub deprecated: its authors' sign that it should not
be used any more, with a note on its page on npmjs.com. This one says
that chalk has its own types, so you do not need the stub.
Bad — trusts the icon, and installs a
description that nothing reads.
Good — nothing to run: reads the
label first, finds chalk's own description, and installs nothing.
The Bad command prints this:
The last line is the check lesson 9.2 explained: npm compared every
package in the project with a public list of known security problems
("vulnerabilities") and found none. There is not one warning, and the
time, 1s (one second), will differ. npm skips the stub's newest,
deprecated version and installs @types/chalk 0.4.31, written in 2016
for chalk 0.4, a version from 2013. The check still passes: TaskKit
does not import chalk yet, and once it does (lesson 14.3), TypeScript
reads chalk's own description first and never the other one. Nothing
tells you that TaskKit's package.json now lists a description of that
2013 chalk, and the next person to read it is misled.
So the icon is a hint. Before you install, the package's
package.json tells you where its description is. After you install
and import it, the check decides, as in lesson 9.3: no TS7016 on
the import line means the package brought its own description. Where
you have the choice, built-in types are the better sign: the
same people write the code and its description and change them
together. An @types description is written by volunteers, and a new
version of the package can come out before its description catches up.
Predict before you look
TaskKit gets commander in lesson 14.4, for its commands. Here are
two lines of its package.json.
Predict
Which file does the check read for commander's description?
The common mistake: a package its authors left
A package can pass three questions and still be one to leave alone,
and npm says so as it installs it.
Common mistake
Installing a package from an old tutorial
You want TaskKit to read something from a web API (application
programming interface: the agreed way one program asks another for
data, lesson 12.4), and a tutorial from a few years ago starts with:
npm installs it, and prints among its first lines, broken here to
fit:
Two more npm warn deprecated lines come before it, for packages
request needs, and further down it ran the same check as before and
found flaws: 5 vulnerabilities (3 moderate, 2 critical). Deprecated,
here, means its authors have stopped working on it: no fixes, no new
versions. request was last published in February 2020. npm installs it anyway,
because you asked, and leaves the warning for you to read.
npm warn deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
The fix
Take it back out. npm uninstall is the opposite of npm install: it
removes the package, and the packages it brought, from node_modules,
and its line from package.json.
The time at the end is in milliseconds (ms) and will differ. For this
job you need no package at all: fetch, built into Node, gets data
from a web API (lesson 12.4).
npm warn deprecated is the third question answered for you, and the
answer is no. Read the whole line, because it often says what to use
instead; then npm uninstall the package before your code comes to
depend on it.
Pass all four tasks to complete the lesson with practice. Reach the end without them and it counts as read only.
Exercises
These run in your browser, so they ask about packages rather than
install them. Open the pages on npmjs.com to try any of them for real.
Recap
Recap · 3 questions
Check yourself
What does a library cost you?
Check yourself
npm warns that your package is deprecated. What now?
Check yourself
Why are built-in types a better sign than @types?
0 of 0 answered.
A cheat sheet to keep
Cheat sheet
Why libraries exist, and how to choose one
What things are
Word
What it means
Library
A package of code your program imports and calls
package.json
The label: name, version, needs, where its files are
"types" in package.json
The package's own description file
"exports"
What a package hands to code that imports it
Readme
What the package does, and how to call it
Deprecated
Marked by its authors: do not use it
Stub
An empty @types package for one with its own types
Four questions
Ask
Where to look
Does it do the job?
The readme
Do many projects use it?
Weekly Downloads
Is anyone looking after it?
Last publish, and what the readme says
Where are its types?
"types" in its package.json, else @types
Signs and commands
Sign or command
What it means
npm warn deprecated
Its authors stopped: pass it over
DT icon
A hint only: read package.json, then the check decides
Built-in types
The better sign: changed together with the code
An old last publish
Fine for a small, finished job
npm uninstall request
Remove it from node_modules and package.json
Where to go next
You can now say what a library gives you and what it costs, find a
package's code and description in its folder and its package.json,
and ask the four questions before anything goes into TaskKit: the
job, the downloads, who looks after it, and where its types are.
Next is Staying safe: lockfiles, pinned versions, and what a
supply-chain attack is, where you see how a package that passed all
four questions can still change under you, and how to keep TaskKit on
the versions you checked.
Before you move on, open node_modules/boxen/package.json in VS Code
and find its "types" line: which file does it name? Then open
lodash's page on npmjs.com and answer the four questions for it
yourself.
Into the package. boxen uses chalk, so npm put it on the shelf too.
The label, package.json; a readme and a licence for you; source.
Into the folder that holds what the package does.
index.js is the code Node runs; index.d.ts (d for declaration), the
description.
chalk is already in TaskKit: boxen brought it in lesson 9.2
Into the package. boxen uses chalk, so npm put it on the shelf too.
The label, package.json; a readme and a licence for you; source.
Into the folder that holds what the package does.
index.js is the code Node runs; index.d.ts (d for declaration), the
description.
chalk is already in TaskKit: boxen brought it in lesson 9.2
All 4 steps shown.Step 1 of 4: cd node_modules/chalk → /home/ana/projects/taskkit/node_modules/chalkStep 2 of 4: ls → /home/ana/projects/taskkit/node_modules/chalkStep 3 of 4: cd source → /home/ana/projects/taskkit/node_modules/chalk/sourceStep 4 of 4: ls → /home/ana/projects/taskkit/node_modules/chalk/source
All 4 steps shown.
Exercise · Read the code
Which one to pass over
TaskKit could read its commands with one of three packages. Here is
what their pages said on 25 October 2026. Which one do you pass over?
commander: readme shows how to define commands; hundreds of
millions of downloads a week; last publish 5 months ago; TS icon.
minimist: readme says "parse argument options"; about a hundred
million a week; last publish in 2023; DT icon.
optimist: its readme opens with "DEPRECATION NOTICE"; millions a
week; last publish in 2014; DT icon.
Exercise · Read the code
Too old to use
ms turns text like "2 days" into milliseconds. Its page: over a
hundred million downloads a week, no other packages needed, and a DT
icon. The version npm installs, 2.1.3, came out in December 2020; the
page's Last publish is newer only because of test versions that
npm does not install. Should TaskKit pass it over because the version
it gets is years old?
Outputtext
added 1 package, and audited 22 packages in 1s14 packages are looking for funding run `npm fund` for detailsfound 0 vulnerabilities
Outputtext
npm warn deprecated request@2.88.2: request has been deprecated, seehttps://github.com/request/request/issues/3142added 47 packages, and audited 68 packages in 2s
Outputtext
removed 47 packages, and audited 21 packages in 486ms
This program prints the commands to add date-fns and lodash to a
project; lodash is a set of ready-made helpers. Both pages show the DT
icon. date-fns's package.json has
"types" lines inside "exports"; lodash's has no "types" line at
all. Fix the plan, so it prints npm install date-fns,
npm install lodash and npm install --save-dev @types/lodash, in
that order.
Loading the editor…
Exercise · Write the code
Write the verdict
Write the body of verdict, so it gives back Pass over for a
deprecated package or one with no types at all,
Install it and its @types for one whose description is in @types,
and Install it for one with its types built in. The program then
prints Pass over, Install it and its @types and Install it.