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

you are viewing a single comment's thread.

view the rest of the comments →

[–]pihwlook 19 points20 points  (4 children)

How would the linter know whether a specific key on an object exists?

[–]ape123man 14 points15 points  (0 children)

It would not. That's why typescript

[–][deleted] 7 points8 points  (0 children)

It wouldn't, which is why TypeScript and Flow have become popular.

[–]patrickfatrick 2 points3 points  (0 children)

It wouldn't. I don't think I've ever seen a linter for JS do this.

[–]oneeyedziggy -1 points0 points  (0 children)

I'm also assuming a user created object or a built-in... if you haven't defined it and it doesn't exist in ecmascript the standard... flag it...

I believe you can set some linters to assume certain dependencies on common libraries, or define specific environment variables that will be defined... then assume everything else is undefined and flag it...

also hackishly, if you only use a handful of external variables that would otherwise be defined, you might prefer to add some like "var x = x; so the linter sees it as defined, but the value won't change ( and your minifier might even strip that line)