Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeScript exports #6703

Merged
merged 5 commits into from
Mar 14, 2023
Merged

Fix TypeScript exports #6703

merged 5 commits into from
Mar 14, 2023

Commits on Mar 12, 2023

  1. Configuration menu
    Copy the full SHA
    d980094 View commit details
    Browse the repository at this point in the history
  2. Fix TypeScript exports

    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')
    ```
    remcohaszing committed Mar 12, 2023
    Configuration menu
    Copy the full SHA
    bbca65f View commit details
    Browse the repository at this point in the history

Commits on Mar 13, 2023

  1. Configuration menu
    Copy the full SHA
    f31f9c5 View commit details
    Browse the repository at this point in the history
  2. Remove redundant tsconfig option allowJs

    `checkJs` implies `allowJs`.
    remcohaszing committed Mar 13, 2023
    Configuration menu
    Copy the full SHA
    3e70a14 View commit details
    Browse the repository at this point in the history

Commits on Mar 14, 2023

  1. Replace vendored type definitions

    They have been published to DefinitelyTyped. The published packages are
    now used as dev dependencies instead.
    remcohaszing committed Mar 14, 2023
    Configuration menu
    Copy the full SHA
    a4275a3 View commit details
    Browse the repository at this point in the history