jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.61k stars 4.03k forks source link

typescipt enum is stored as string in model #7556

Closed drummer3333 closed 6 years ago

drummer3333 commented 6 years ago
Overview of the issue

I can't compare the speechToTextJob.status with the static enum values JobStatus.* because the field is set to string values.

Motivation for or Use Case

We use Angular 5 in the frontend. I want to test the status field of the incoming data in the onSuccess method of speech-to-text-job.component.ts. Because the incoming data is of type String but model has the enum type, I have to cast the field to compare it to a String.

Reproduce the error

in speech-to-text-job.component.ts add this to onSuccess:

        if (this.speechToTextJobs.find((item) => item.status === JobStatus.WAITING || item.status === JobStatus.PENDING)) {
            Observable.timer(2000).first().subscribe(() => this.loadAll());
        }

Timer is never started.

Using JHipster version installed locally in current project's node_modules
Executing jhipster:info
Options:
Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
compass-web-app@0.0.0 C:\git\compasswebapp                                                                                                                                                                                
`-- generator-jhipster@4.14.1                                                                                                                                                                                             
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
                                                                                                                                                                                                                     
{                                                                                                                                                                                                                         
  "generator-jhipster": {                                                                                                                                                                                                 
    "promptValues": {                                                                                                                                                                                                     
      "packageName": "com.zdfdigital",                                                                                                                                                                                    
      "nativeLanguage": "en"                                                                                                                                                                                              
    },                                                                                                                                                                                                                    
    "jhipsterVersion": "4.14.1",                                                                                                                                                                                          
    "baseName": "CompassWebApp",                                                                                                                                                                                          
    "packageName": "com.zdfdigital",                                                                                                                                                                                      
    "packageFolder": "com/zdfdigital",                                                                                                                                                                                    
    "serverPort": "8080",                                                                                                                                                                                                 
    "authenticationType": "jwt",                                                                                                                                                                                          
    "cacheProvider": "no",                                                                                                                                                                                                
    "websocket": "spring-websocket",                                                                                                                                                                                      
    "databaseType": "sql",                                                                                                                                                                                                
    "devDatabaseType": "h2Disk",                                                                                                                                                                                          
    "prodDatabaseType": "mysql",                                                                                                                                                                                          
    "searchEngine": false,                                                                                                                                                                                                
    "messageBroker": false,                                                                                                                                                                                               
    "serviceDiscoveryType": false,                                                                                                                                                                                        
    "buildTool": "maven",                                                                                                                                                                                                 
    "enableSocialSignIn": false,                                                                                                                                                                                          
    "enableSwaggerCodegen": false,                                                                                                                                                                                        
    "jwtSecretKey": "replaced-by-jhipster-info",                                                                                                                                                                          
    "clientFramework": "angularX",                                                                                                                                                                                        
    "useSass": true,                                                                                                                                                                                                      
    "clientPackageManager": "yarn",                                                                                                                                                                                       
    "applicationType": "monolith",                                                                                                                                                                                        
    "testFrameworks": [                                                                                                                                                                                                   
      "gatling",                                                                                                                                                                                                          
      "cucumber",                                                                                                                                                                                                         
      "protractor"                                                                                                                                                                                                        
    ],                                                                                                                                                                                                                    
    "jhiPrefix": "jhi",                                                                                                                                                                                                   
    "enableTranslation": true,                                                                                                                                                                                            
    "nativeLanguage": "en",                                                                                                                                                                                               
    "languages": [                                                                                                                                                                                                        
      "en"                                                                                                                                                                                                                
    ]                                                                                                                                                                                                                     
  }                                                                                                                                                                                                                       
}                                                                                                                                                                                                                         
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
                                                                                                                                                                                                                                                                                                                                                                                                                                    
entity SpeechToTextJob (speech_to_text_job) {                                                                                                                                                                             
  recognizedText TextBlob,                                                                                                                                                                                                
  errorText String maxlength(2000),                                                                                                                                                                                       
  status JobStatus                                                                                                                                                                                                        
}                                                                                                                                                                                                                         

enum JobStatus {                                                                                                                                                                                                          
  WAITING,                                                                                                                                                                                                                
  PENDING,                                                                                                                                                                                                                
  COMPLETED,                                                                                                                                                                                                              
  FAILED                                                                                                                                                                                                                  
}                                                                                                                                                                                                                         

paginate SpeechToTextJob with pagination                                                                                                                                                                    
service SpeechToTextJob with serviceClass                                                                                                                                                                                 

Environment and Tools

java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

git version 2.16.2.windows.1

node: v9.8.0

npm: 5.6.0

bower: 1.8.2

yeoman: 2.0.1

yarn: 1.5.1

Docker version 18.03.1-ce, build 9ee9f40

docker-compose version 1.21.0, build 5920eb08

Congratulations, JHipster execution is complete!

Browsers and Operating System

Windows 10 / Firefox 59

ruddell commented 6 years ago

By default, JobStatus.WAITING === 0. In the PR, I changed the entity enums to use string enums as documented in the Typescript docs which makes JobStatus.WAITING === 'WAITING'. https://www.typescriptlang.org/docs/handbook/enums.html#string-enums