angular - Typescript: Receiving errors when typing an object or array as rxjs Subject variable -


my snippet.

signupinfo: {code: string, message: string}       = new subject<{code: string, message: string}>(); 

the error atom editor gives me.

type 'subject<{code: string, message: string}>' not assignable type '{code: string, message: string}'. property 'code' missing in type 'subject<{code: string, message: string}>'.

typescript error

removing typings in variable, replacing type any or {} removes error.

signupinfo = new subject<{code: string, message: string}>(); signupinfo: = new subject<{code: string, message: string}>(); signupinfo: {} = new subject<{code: string, message: string}>(); signupinfo = new subject<{code: string, message: string}>(); signupinfo: any[] = new subject<model[]>(); 

i used put typeings on every variable in ts, have no problems when passing regular types such string number booleans etc. when passing array or object subject variable typings seems im not allowed it.

what correct way of typing object or array subject variable in typescript?

the correct way set:

signupinfo: subject<{code: string, message: string}> = new subject<{code: string, message: string}>(); 

actually think don't need set type because it's automatically assumed when you're assigning instance of subject<{code: string, message: string}>. if try call signupinfo.next(1) compiler throw type error.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -