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

Generating JS Code variable names as if were declarations. which are not possible parse/import js into react or compile #45236

Closed
wesleyolis opened this issue Jul 29, 2021 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@wesleyolis
Copy link

Bug Report

🔎 Search Terms

Variants of this: [ts compile] generating js ([variable names] [declarations ])

🕗 Version & Regression Information

Introduce after version 4.2.4 by the looks of it, version 4.3.2 features the bug.
nt-bugs
This issue also exists in the latest Nightly build, sorry.

Please keep and fill in the line that best applies:
-->

  • This changed between versions 4.2.4 and 4.3.2, there was no 4.3.1 to install.

1-Input

import * as axios from 'axios'; //"version": "0.18.0"

export class IResponseError extends Error {

    constructor(message:string, public axiosResponse:axios.AxiosResponse<any>) {

        super(message);
    }
}

1-Output

 class IResponseError extends Error {
     axiosResponse; //** random line of generated code, which stops imports into react and things, it shouldn't be here
     constructor(message, axiosResponse) {
         super(message);

2-Input

export class GatewayConfigAPI {

   constructor(private endpoint: string) {        

       this.endpoint = endpoint.substring(0, endpoint.length - 1);
   }
}

2-Output

Module parse failed: Unexpected token (54:12)
You may need an appropriate loader to handle this file type.
  | })(IGatewayConfigController = exports.IGatewayConfigController || (exports.IGatewayConfigController = {}));
  | class GatewayConfigAPI {
  |     endpoint;	// ***************Line 54 this line should not have been generated.
  |     constructor(endpoint) {
  |         this.endpoint = endpoint;// unessary line
  this.endpoint = endpoint.substring(0, endpoint.length - 1);
}

3 - Input:

import {IsString, IsBoolean, ValidateNested} from 'class-validator'

export class IDONetMapsEDIConfigShare {
    
    @IsString()
    nethost: string;

    @IsString()
    netshare: string;

    @IsString()
    username: string;

    @IsString()
    password: string;        
}

3- Output:

class IDONetMapsEDIConfigShare {
    nethost;   // This shouldn't be here
    netshare;  // This shouldn't be here
    username;  // This shouldn't be here
    password;  // This shouldn't be here
}

4-Input

export class IDONetMapsEDIConfigResponse {

    constructor(clone: INetMapsEDIServicesConfigComplete, activeStatus: string) {     
        this.enabled = clone.enabled;
        this.netMapsEDI = clone.netMapsEDI !== undefined ? clone.netMapsEDI : null;
        this.activeStatus = activeStatus;
        // look at just writting a generic class that does this, where we pick using and clone, extends, use type hack I know later.
    }

    @IsBoolean()
    enabled:boolean;    

    @IsString()
    activeStatus:string;    

    @ValidateNested()
    //@Type(() => IDONetMapsEDIConfigShare)
    netMapsEDI: IDONetMapsEDIConfigShare | null; 
}

4 - Output JS

class IDONetMapsEDIConfigResponse {
    constructor(clone, activeStatus) {
        this.enabled = clone.enabled;
        this.netMapsEDI = clone.netMapsEDI !== undefined ? clone.netMapsEDI : null;
        this.activeStatus = activeStatus;
        // look at just writting a generic class that does this, where we pick using and clone, extends, use type hack I know later.
    }
    enabled;// This should not be here.
    activeStatus;
    //@Type(() => IDONetMapsEDIConfigShare)
    netMapsEDI;
}

4 - Expected JS

class IDONetMapsEDIConfigResponse {
    constructor(clone, activeStatus) {
        this.enabled = clone.enabled;
        this.netMapsEDI = clone.netMapsEDI !== undefined ? clone.netMapsEDI : null;
        this.activeStatus = activeStatus;
        // look at just writting a generic class that does this, where we pick using and clone, extends, use type hack I know later.
    }
    activeStatus;
    //@Type(() => IDONetMapsEDIConfigShare)
    netMapsEDI;
}

Kind Regards,

Wesley Oliver

@MartinJohns
Copy link
Contributor

MartinJohns commented Jul 29, 2021

This is working as intended. The behaviour can be controlled with the useDefineForClassFields flag. For the ESNext target this is enabled by default, for all earlier targets it's disabled by default.

This is done to align with the future ECMAScript standard. See #45076.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jul 29, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants