Skip to content

Invalid apex.d.ts type defs are generated by the VSCode extension #5244

Open
@guillaumelachaud

Description

@guillaumelachaud

Description

Steps to Reproduce

  • Create a new SFDX Project using the VSCode extension
  • Enable Typescript support
  • Use refreshApex in a LWC component

Expected Results

The type definitions have been generated properly and the component can compile

Actual Results

tsc will complain:

Module '"@salesforce/apex"' has no exported member 'refreshApex'.ts(2305)

Which appears to be true. An apex.d.ts appears to have been generated by the VSCode extension in .sfdx/typings/apex/ with the following code:

declare module "@salesforce/apex" {
    /**
     * Identifier for an object's field.
     */
    export interface FieldId {
        /** The field's API name. */
        fieldApiName: string;
        /** The object's API name. */
        objectApiName: string;
    }

    /**
     * Services for Apex.
     */
    export interface ApexServices {
        /**
         * Refreshes a property annotated with @wire. Queries the server for updated data and refreshes the cache.
         * @param wiredTargetValue A property annotated with @wire.
         * @returns Promise that resolves to the refreshed value. If an error occurs, the promise is rejected.
         */
        refreshApex: (wiredTargetValue: any) => Promise<any>;

        /**
         * Gets a field value from an Apex sObject.
         * @param sObject The sObject holding the field.
         * @param field The field to return.
         * @returns The field's value. If it doesn't exist, undefined is returned.
         */
        getSObjectValue: (sObject: object, field: string | FieldId) => any;
    }
}

The type def expose an interface with refreshApex but it is not clear how to use this. Rewriting the type def manually as follows works:

declare module "@salesforce/apex" {
    export function refreshApex(wiredTargetValue: any): Promise<any>;
  }

Is it expected for the generated apex.d.ts to be incorrect?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    External: Other SalesforceCategorizes issue or PR as related to Salesforce related features.typescriptTypescript related bugs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions