In normal *.d.ts file (definition files for typescript), we can normally use
declare ***
export interface ***
but there is also this
/// <reference types="react-scripts" />
generated by create-react-app, what does it mean and can we actually use xml like syntax in *.d.ts files and what other syntax can we use?
Triple-slash directives are single-line comments containing a single XML tag. The contents of the comment are used as compiler directives. Triple-slash directives are only valid at the top of their containing file.
The react-app-env. d. ts references the types of react-scripts , and helps with things like allowing for SVG imports.
A /// <reference types="..." />
directive declares a dependency on a package.
The process of resolving these package names is similar to the process of resolving module names in an import statement. An easy way to think of these triple-slash-reference-types directives is as an import for declaration packages.
For example, including /// <reference types="node" />
in a declaration file declares that this file uses names declared in @types/node/index.d.ts
and thus, this package needs to be included in the compilation along with the declaration file.
Use these directives only when you’re authoring a d.ts file by hand. More information: https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html
In your case, /// <reference types="react-scripts" />
imports various names declared in the node_modules/react-scripts/lib/react-app.d.ts
file.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With