javascript - Using generic types in constructor call without using types in the parameters -


is possible use generics in constructor call without using types in parameters that, or there way of doing this?

type personprops = {   name: string, }  class model<p> {   label: string;    constructor(label: string) {     this.label = label;   }    create(props: p): promise<any> { ... } }  const person = new model<personprops>('person'); 

edit:

i following flow errors in visual studio code , no autocomplete results @ all:

test.js:11 11: const person = new model<personprops>('person');                     ^^^^^^^^^^^^^^^^^^^^^ boolean. type cannot compared 11: const person = new model<personprops>('person');                                           ^^^^^^^^ string  test.js:11 11: const person = new model<personprops>('person');                               ^^^^^^^^^^^ personprops. type referenced value position   5: type personprops = {           ^^^^^^^^^^^ type personprops 

you don't need (and in fact cannot) specify type parameter there:

const person = new model('person'); 

if specify full type, type parameter, person variable, can add type annotation:

const person: model<personprops> = new model('person'); 

the errors seeing due fact < , > characters parse "less than" , "greater than" in context.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -