The first change that was made, is that all `declare module`
declarations were replaced. `declare module` is meant for declaring
another module that doesn’t match the package name, for example
`@types/node` uses this to declare `fs`. To accommodate this,
`typeRoots` was replaced with `paths`. Note that this change causes a
lot of indentation changes, but no actual code changes.
Next up was fixing the types of stylelint. Stylelint uses
`module.exports =`. The correct type definition for this is `export =`.
The type definitions also export a number of types. The correct way to
export types in combination with `export =`, is to declare a namespace.
If a namespace has no explicit exports, all members are implicitly
exported. If a namespace has at least one export, all unexported members
are private. I prefer the former. All exported members have been moved
inside the `stylelint` namespace, and had their `export` declarations
removed. All private types are kept outside of the namespace. This
causes more diffs, but no type definitions have been modified.
If `module.exports` is a function or class, static properties are
ideally declared in the namespace. However, `stylelint` extends
`postcss.PluginCreator`, which has a property `postcss`. Because of
this, the type of `stylelint` has been kept as-is.
This change affects all users who rely on synthetic default exports, but
haven’t configured TypeScript correctly. ESM users should specify:
```json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
```
or better:
```json
{
"compilerOptions": {
"module": "node16"
}
}
```
CommonJS users who wish to use ESM syntax and transpile, should specify
the following, although I personally recommend against this:
```json
{
"compilerOptions": {
"esModuleInterop": true
}
}
```
The correct way to consume this package using CommonJS is one of the
following. This change is also reflected in the internal stylelint type
annotations and type test:
```ts
// TypeScript
import * as stylelint from 'stylelint'
import stylelint = require('stylelint')
// JavaScript
const stylelint = require('stylelint')
```