Skip to content

💡 Possibility to import RawConfiguration or something similar for dynamic configuration #1634

@armand-dfl

Description

@armand-dfl

Suggest an idea for Knip

In my use case, I need to create a custom function that accepts a Knip config object as a parameter, something like this:

export function createConfig({
  compilers,
  ignoreDependencies = [],
  ...config
}: KnipConfig = {}): KnipConfig {
  return {
    ...,
    ...config,
  }
}

The problem is that KnipConfig seems to be a union of several types rather than just the plain config object type. I could not find any documentation mentioning the underlying types.

After looking through node_modules, I found RawConfiguration, which appears to match my use case better, but it cannot be imported.

Because of this, I currently have to do something like:

import type { KnipConfig } from "knip"
type KnipConfigObject = Exclude<KnipConfig, (...args: never[]) => unknown>
export function createConfig({
  compilers,
  ignoreDependencies = [],
  ...config
}: KnipConfigObject = {}): KnipConfig {
  return {
    ...,
    ...config,
  }
}

It would be useful to expose the object config type separately, or otherwise make it possible to import the relevant subtype of KnipConfig.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions