Skip to content

Incomplete or Incorrect null Return Type in transform Method #620

@Imran-imtiaz48

Description

@Imran-imtiaz48

The transform function in the sass plugin returns null early if certain conditions aren't met (e.g., when the plugin is not to be used or the input is not a string). However, the declared return type of the function is Promise<d.PluginTransformResults>, and returning null directly contradicts this type expectation.

This type mismatch can lead to runtime errors or issues with static type checking in TypeScript, especially when consuming code assumes that transform always returns a Promise. The correct approach would be to return Promise.resolve(null) if null is an acceptable value by the plugin system, or better yet, adjust the return type to Promise<d.PluginTransformResults | null> if null is intentionally valid.

Suggested Fix:
transform(sourceText: string, fileName: string, context: d.PluginCtx): Promise<d.PluginTransformResults>

to:
transform(sourceText: string, fileName: string, context: d.PluginCtx): Promise<d.PluginTransformResults | null>
This will make the function's return behavior consistent and avoid potential type errors during usage.

Activity

christian-bromann

christian-bromann commented on Jun 23, 2025

@christian-bromann
Member

@Imran-imtiaz48 thanks for raising the issue. This makes sense to me, mind raising a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @christian-bromann@Imran-imtiaz48

        Issue actions

          Incomplete or Incorrect null Return Type in transform Method · Issue #620 · stenciljs/sass