Skip to content

bug: Incorrect Plugin Transform return type #6231

Open
@Altioc

Description

@Altioc

Prerequisites

Stencil Version

4.29.2

Current Behavior

The type definition for the transform method of a Plugin incorrectly defines the return value as:

Promise<PluginTransformResults> | PluginTransformResults | string;

Expected Behavior

Based on the code the definitions should be something more like:

export interface Plugin {
  name?: string;
  pluginType?: string;
  load?: (id: string, context: PluginCtx) => Promise<string> | string;
  resolveId?: (importee: string, importer: string, context: PluginCtx) => Promise<string> | string;
  transform?: (
    sourceText: string,
    id: string,
    context: PluginCtx,
  ) => Promise<PluginTransformResults> | PluginTransformResults;
}

export type PluginTransformResults = PluginTransformationDescriptor | string | null;

export interface PluginTransformationDescriptor {
  code?: string;
  map?: string;
  id?: string;
  diagnostics?: Diagnostic[];
  dependencies?: string[];
}

System Info

System: node 20.18.0
    Platform: windows (10.0.26100)
   CPU Model: AMD Ryzen 9 9950X 16-Core Processor             (32 cpus)
    Compiler: C:\Users\user\Documents\GitHub\stencil-type-declaration-bug\node_modules\@stencil\core\compiler\stencil.js  
       Build: 1744045416
     Stencil: 4.29.2
  TypeScript: 5.5.4
      Rollup: 4.34.9
      Parse5: 7.2.1
      jQuery: 4.0.0-pre
      Terser: 5.37.0

Steps to Reproduce

  1. Create a plugin with a transform method that returns null
  2. Observe the Typescript language server getting mad at you

Code Reproduction URL

https://github.com/Altioc/stencil-type-declaration-bug/blob/ab78c5286d8e002fbe44048a85b6e2f02b444d26/stencil.config.ts#L7

Additional Information

I am willing to make a PR addressing this issue assuming it's an issue that the maintainers think needs addressing and that they think needs addressing in this way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions