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
Post a Comment