Install pluralize, a package that brings no description, and meet the check’s TS7016. Learn what a .d.ts description is, give TypeScript one from @types, tell from the TS and DT icons on npmjs.com whether a package needs it, and see why the check says --types node but never --types pluralize.
TypeScript
Fundamentals
Types for packages: `@types` and the `types` setting. Read this lesson at .
Tested with TypeScript 7.x · Node.js LTS
Lesson 9.2 gave TaskKit a framed banner and three short commands. Add
one task with npm start add milk, and the summary line under
Added: Milk still reads like a form:
Tasks added: 1 of 5, room for 4 more. You would say "1 task
added", and "2 tasks added" for two. An if could pick
between task and tasks, but English is full of other plurals:
box becomes boxes, person becomes people. Someone has
already written a package that knows them.
That package was written for JavaScript, though, and TypeScript
cannot check a call into code it knows nothing about. It is like
being handed a machine with no manual: it may work fine, but you
cannot tell which button does what. By the end of this lesson
TaskKit says "1 task added", every call into the new package is
checked, and you know how to find out whether TypeScript will be
able to check a package: a first hint before you install it, and
the answer from the check.
A package with no description
The package is pluralize: give it a word and a number, and it
gives back the word in the right form for that number. In the
taskkit folder, run:
bash
npm install pluralize
Outputtext
added 1 package, and audited 20 packages in 661ms14 packages are looking for funding run `npm fund` for detailsfound 0 vulnerabilities
661ms is 661 milliseconds, thousandths of a second; your time
will differ. pluralize needs no packages of its own, so this time
npm (Node package manager) added one. TaskKit calls it every time
it runs, so it went into dependencies, beside boxen. Now use it.
In print.ts, add a line under the boxen import:
print.tsts
import boxen from "boxen";import pluralize from "pluralize";
Then change the first console.log in printSummary. Only that
line changes; the lines after it stay as they are:
pluralize("task", 2, true) gives back "2 tasks": the word, then
the number, then true, which asks for the number in front of the
word. Now check, as always before you run:
bash
npm run check
npm prints its two > lines, and then TypeScript refuses with
TS7016 (TS for TypeScript, then the number of the message). The
message is two long lines in your terminal, broken here to fit the
page: the first ends with 'any' type., the second starts with
Try:
What the check printstext
print.ts:2:23 - error TS7016: Could not find a declaration file formodule 'pluralize'.'/Users/ana/projects/taskkit/node_modules/pluralize/pluralize.js'implicitly has an 'any' type. Try `npm i --save-dev @types/pluralize` if it exists or add a newdeclaration (.d.ts) file containing `declare module 'pluralize';`2 import pluralize from "pluralize"; ~~~~~~~~~~~Found 1 error in print.ts:2
print.ts:2:23 - error TS7016: Could not find a declaration file formodule 'pluralize'.'C:/Users/ana/projects/taskkit/node_modules/pluralize/pluralize.js'implicitly has an 'any' type. Try `npm i --save-dev @types/pluralize` if it exists or add a newdeclaration (.d.ts) file containing `declare module 'pluralize';`2 import pluralize from "pluralize"; ~~~~~~~~~~~Found 1 error in print.ts:2
print.ts:2:23 - error TS7016: Could not find a declaration file formodule 'pluralize'.'/home/ana/projects/taskkit/node_modules/pluralize/pluralize.js'implicitly has an 'any' type. Try `npm i --save-dev @types/pluralize` if it exists or add a newdeclaration (.d.ts) file containing `declare module 'pluralize';`2 import pluralize from "pluralize"; ~~~~~~~~~~~Found 1 error in print.ts:2
A declaration file is what the course has called a
description since lesson 2.8, and it is the machine's manual: a
file that tells TypeScript what a package holds and the type of
each thing in it, such as "pluralize takes a string and a number
and gives back a string". pluralize brought its code and no such
file. "Implicitly has an 'any' type" is the complaint lesson 5.1
met as TS7006: with nothing to go on, TypeScript has to treat
pluralize as any, which checks nothing (lesson 8.5), so it
refuses the import.
Node would run TaskKit without a complaint: it runs the code, and
the code is there. Only the check refuses. The line that starts
with Try names the two ways out; npm i in it is short for
npm install. The first one, @types, is this lesson; writing a
description yourself is for Level 2.
Code and description on the shelf
A description lives in a file whose name ends in .d.ts, the
d for declaration: a TypeScript file that holds types only, with
no code to run. boxen brought one, which is why lesson 9.2's check
passed without a word about boxen. Besides the code and its
description, a package folder holds a readme, which says what the
package does, a licence, which says what you may do with it, and
its own package.json.
In VS Code (Visual Studio Code, your editor), open node_modules
in the Explorer, the list of your project's files, then the
boxen and pluralize folders inside it, and compare:
index.d.tsindex.jslicensepackage.jsonreadme.md
The description
boxen
Does: Brings its code and its description
LICENSEReadme.mdpackage.jsonpluralize.js
pluralize
Never: Brings no description for TypeScript
LICENSEREADME.mdindex.d.tspackage.json
The description
@types/pluralize
Does: Brings a description, and no code
Code is for Node, a .d.ts description is for TypeScript
The third folder is not on your shelf yet. It is the description
somebody else wrote for pluralize, and the next section installs it.
@types: descriptions written by others
Many packages were written in JavaScript before TypeScript was
common, and their authors never wrote a description. So volunteers
write them, in a shared project called DefinitelyTyped, and each
one is published on npm as a package of its own, named
@types/ and the package's exact name. A name that starts
with @ belongs to a family of packages: @types/ is the family
of descriptions, and @types/node, which you installed in lesson
2.8, is one of them.
The description is only for the check, and Node never reads it, so
it is a dev (development) dependency:
bash
npm install --save-dev @types/pluralize
Outputtext
added 1 package, and audited 21 packages in 1s14 packages are looking for funding run `npm fund` for detailsfound 0 vulnerabilities
package.json now lists it beside @types/node, under
devDependencies, as "@types/pluralize": "^0.0.33", while pluralize
itself sits under dependencies as "^8.0.0". Most @types packages
copy the first two numbers of the package they describe, @types/ms
2.1 for ms 2.1, and so does @types/node, which is why lesson 2.8
asked for @24. pluralize's was never matched up, so its 0.0.33
need not match pluralize's 8.0.0. Run the check again:
Nothing after the > lines (in the second, tsc, the TypeScript
compiler, is the check itself): the check passed, and you changed
nothing in the check command. Here is how TypeScript found the
description on its own. Switch between the three cases, and press
Next step to walk through each, or let it play:
The check reaches the import line and needs the package's
description.
node_modules/boxen holds index.d.ts. Found on the first
try.
The package had its own description, so TypeScript never looks
here.
Every call to boxen is checked against index.d.ts.
TypeScript looks in the package's own folder, then in @types
All 4 steps shown.Step 1 of 4: TypeScript: reads importStep 2 of 4: Package folder: index.d.ts ✓Step 3 of 4: @types folder: not neededStep 4 of 4: TypeScript: checked ✓
All 4 steps shown.
TypeScript
Packagefolder
@typesfolder
TypeScript: reads importreadsimportreadsimport
Package folder: code onlycodeonlycodeonly
@types folder: no foldernofoldernofolder
TypeScript: TS7016TS7016TS7016
Time
The check reaches the import line and needs the package's
description.
node_modules/pluralize holds pluralize.js and no .d.ts.
node_modules/@types/pluralize does not exist yet.
No description anywhere. TypeScript treats pluralize as
any, which checks nothing, and refuses the import.
TypeScript looks in the package's own folder, then in @types
All 4 steps shown.Step 1 of 4: TypeScript: reads importStep 2 of 4: Package folder: code onlyStep 3 of 4: @types folder: no folderStep 4 of 4: TypeScript: TS7016
All 4 steps shown.
TypeScript
Packagefolder
@typesfolder
TypeScript: reads importreadsimportreadsimport
Package folder: code onlycodeonlycodeonly
@types folder: index.d.ts ✓index.d.ts✓index.d.ts✓
TypeScript: checked ✓checked✓checked✓
Time
The check reaches the import line and needs the package's
description.
node_modules/pluralize holds pluralize.js and no .d.ts.
Every call to pluralize is checked against the description
from @types.
TypeScript looks in the package's own folder, then in @types
All 4 steps shown.Step 1 of 4: TypeScript: reads importStep 2 of 4: Package folder: code onlyStep 3 of 4: @types folder: index.d.ts ✓Step 4 of 4: TypeScript: checked ✓
All 4 steps shown.
Your import line did not change either. You import the package
that holds the code, from "pluralize", and the check finds its
description by that name; an import that names an @types package
is refused (the check says
TS6137: Cannot import type declaration files.). Run TaskKit:
bash
npm start add milk bread
Outputtext
> start> node index.ts add milk bread┌ TaskKit 0.1 ───────────────┐│Your tasks, in your terminal│└────────────────────────────┘Added: MilkAdded: Bread2 tasks added, room for 3 moreList 40% fullYour list, A to Z:#2 [todo] Bread, due: not set#1 [todo] Milk, due: not set
With one task, the line reads 1 task added, room for 4 more.
What the description checks
The description says which order pluralize wants: the word first,
then the number. Swap them by mistake, as here, and the check
refuses, its first line broken here to fit:
print.tsts
`${pluralize(added, "task", true)} added, room for ${room} more`
What the check printstext
print.ts:21:18 - error TS2345: Argument of type 'number' is notassignable to parameter of type 'string'.21 `${pluralize(added, "task", true)} added, room for ${room} more` ~~~~~Found 1 error in print.ts:21
Without the description, the check could only refuse the import;
it could not see this mistake, and Node would run straight into
it. Run npm start add milk with the swapped line, and pluralize's
own code calls toLowerCase on what it takes for the word, the
number 1. After Added: Milk, TaskKit prints
word.toLowerCase is not a function instead of the summary: the
same kind of crash lesson 8.5 got from an any. With the
description, you find out before anything runs.
Before you install: the icon on npmjs.com
You need not install a package to get a first hint of whether it
brings a description. On its page on npmjs.com, look right after
the package's name at the top:
a blue TS icon, for TypeScript. Point at it and it reads
"This package contains built-in TypeScript declarations"
(declarations: the site's word for descriptions). boxen's page
has it.
a white DT icon, for DefinitelyTyped. Point at it and it reads
"This package has TypeScript declarations provided by
@types/pluralize". pluralize's page has it, and the icon links to
the @types package.
no icon: npmjs.com knows of no description for it.
The icon is a hint, not the answer. Now and then npmjs.com misses a
description that a package brings, and shows the DT icon for an
@types package nobody needs; Module 14 meets one. The answer is
the check. Install the package alone, import it, and run the check:
if it is clean, the description came with the package; if it says
TS7016, it did not, and that is when you install its @types
package, as you did for pluralize.
At this level, a package the check refuses with TS7016, and that
has no @types package, is one to skip. There is almost always
another that does the same job and brings a description; Module 14
comes back to choosing between packages.
The types setting
One flag has been on the check line since lesson 2.8:
--types node. You did not need --types pluralize for the
description you just installed, so what is the flag for?
TypeScript can load a description in two ways, and lesson 2.8's rule,
that it does not load installed descriptions on its own, holds only
for the second. A package you import is named in an import line, so
TypeScript looks up its description by that name, as the figure above
showed. But process (here process.argv, the argument vector, the
words you typed) comes from no import: Node provides it on its own, so
no line of TaskKit names @types/node. TypeScript loads such a
description only when its types setting lists it, and the list
starts out empty. --types node puts node on it, the name after
@types/, for this one check:
import pluralize from"pluralize";
Found by this name
@types/pluralize
Does: Found by the import line, with no setting
const word =process.argv.at(2);
Known with --types node
@types/node
Does: Loaded only when --types node names it
An import names its package; --types names what nobody imports
node is the only such description TaskKit has. The next lesson
moves this setting, with the rest of the long check line, into a
file.
Predict the check
A friend reads "the types setting" and decides the new description
belongs there. They put pluralize in place of node and check
TaskKit with npx tsc, which starts the tsc in taskkit:
The name has to be exact: @types/, then the package's name as npm
lists it.
Common mistake
One letter short in @types
You type the install from memory:
bash
npm install --save-dev @type/pluralize
npm asks the registry for a package by that name, and there is
none. The first lines of its answer, the second and fourth broken
here to fit:
Outputtext
npm error code E404npm error 404 Not Found - GEThttps://registry.npmjs.org/@type%2fpluralize - Not foundnpm error 404npm error 404 The requested resource '@type/pluralize@*' could notbe found or you do not have permission to access it.
npm error code E404
The fix
Write @types, with the s, and the package's name exactly:
bash
npm install --save-dev @types/pluralize
E404, E for error and 404 the web's number for "not found",
means "no package by that name". GET is npm asking to download
what is at that address, and %2f in the address is how npm
writes the /. Compare the name in the requested resource line
with the package's page on npmjs.com, letter by letter. If the
name is right and E404 stays, there is no @types package for
it, and the package's own page on npmjs.com will have no DT icon
either.
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 the check and npm
rather than run them. Try any of them in TaskKit for real.
Exercise · Read the code
Which one needs @types
You are choosing three packages: dayjs (writes dates as words,
like 31 October), commander (reads commands) and ms (turns
"2 days" into milliseconds). On npmjs.com, dayjs and commander have
a TS icon, and ms has a DT icon. You install all three and import
them, and the check prints TS7016 for ms alone. For which of them do
you also install an @types package?
Exercise · Predict the result
Answer the check
You install minimist, a package that reads the words typed
after a command, with npm install minimist. The check then says
error TS7016: …'minimist'. The package's page has a DT icon. What
command do you run next?
Exercise · Fix the error
Import the package, not its description
This program prints the import line someone added to print.ts
after installing @types/pluralize. The check refuses it with
TS6137: Cannot import type declaration files. Fix it, so the
program prints the line that works.
Loading the editor…
Exercise · Read the code
Without the description
A friend copies TaskKit with pluralize installed but not
@types/pluralize, and writes this line in print.ts, with the
count in quotes by mistake:
ts
console.log(pluralize("task", "2", true));
What does npm run check print?
Recap
Recap · 3 questions
Check yourself
What does the @types/pluralize package hold?
Check yourself
Where does the check look first for pluralize's description?
Check yourself
Why --types node, but never --types pluralize?
0 of 0 answered.
A cheat sheet to keep
Cheat sheet
Types for packages: @types and the types setting
What things are
Word
What it means
Description
A declaration file: what a package holds, with types
.d.ts
A file of types only, with no code to run
@types/pluralize
A description someone else wrote for pluralize
DefinitelyTyped
The shared project that writes @types packages
types setting
The descriptions to load that nothing imports
Commands
Write
To
npm install pluralize
Add the package, code only
npm install --save-dev @types/pluralize
Add its description
--types node
Load Node's description, for process
Rules
Rule
What it means
Own folder, then @types
Where the check looks for a description
TS7016
No description anywhere: look for an @types package
An icon on npmjs.com
A hint only: the check decides
Development only
Node never reads a description
Import the package
from "pluralize", never from "@types/…"
--types stays node
An imported package needs no setting
E404
No package by that name: check the spelling
Where to go next
You can now read a package's icon as a hint, let the check say for
certain whether it brings a description, install one from @types
when it does not, and say why --types node is on the check line
while a package you import needs no flag there. TaskKit says
"1 task added", and every call into pluralize is checked.
Next is A ready-made tsconfig.json: strict, and the flags
that keep TypeScript in sync with Node. The check line has grown
to three flags and a file name; there you write them once in a
settings file, types among them, and the check becomes plain
tsc.
Before you move on, run npm start add milk bread eggs tea rice and
read the summary line for a full list. Then open the npmjs.com pages
of boxen and ms, and see which icon each one has after its name.