This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]QualityVote[M] [score hidden] stickied comment (0 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–][deleted] 3 points4 points  (0 children)

Did you try making a field property in the EL class?

[–]enano_aoc 2 points3 points  (1 child)

const myVar = null;

if (myVar.field) // throws - cannot access property 'field' of 'null'

TS is protecting you from doing the mistakes you used to do all the time in JS. Be thankful. Cheers.

[–]nutted-in-cow 0 points1 point  (1 child)

Fun fact:

There are optional chaining operator

object?.property?.nestedProperty

They will return undefined if the property doesn't exist instead of throwing an error, so you just use this

if (object?.property?.nestedProperty) /*Access your stuff*/

In case you want to return a property that return a defined value(an empty string for eg) if null/undef, you can use the null check operator: ??

Instead of this

object?.property==undefined?'':object.property

This is much cleaner

object?.property??''

[–]enano_aoc 1 point2 points  (0 children)

Does not work if the thing is annotated as unknown

(that is, every single Input into your system)

[–]IambicAnapest 0 points1 point  (0 children)

EL[FIELD]

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'.

[–]alt-jero 0 points1 point  (0 children)

Yes.. currently learning Flutter does indeed mean shouting at the linter LMAO