question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dangerous "name" (and potentially others) global

See original GitHub issue

TypeScript Version: 2.6.0-dev.20170913

Code

if (name === "asdf") {
  console.log("asdf")
}

https://www.typescriptlang.org/play/#src=if (name %3D%3D%3D "asdf") {%0D%0A console.log('hello')%0D%0A}

Expected behavior:

Error out

Actual behavior:

More than once, I had a “local” variable called name, outside a block scope, and it didn’t warn me that it’s not defined (or used before declaration). even though, in my code, event.name is a string, the global name variable is of type never. it’s defined in lib.dom.d.ts, along with other “juicy” global names that will provide some confusion, like length, external, event, closed

image

image

one ‘fix’ (that would be a breaking change) would to make lib.dom-globals.d.ts (the propertiers that are usually accessible through window variable) and make it an opt-in in tsconfig.json compilerOptions.lib array

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:38
  • Comments:74 (33 by maintainers)

github_iconTop GitHub Comments

15reactions
ericandersoncommented, Jul 1, 2019

Perhaps we could get a compiler flag for noImplicitGlobalThis? Thus using name would be an error but if you want to use globalThis.name you could?

15reactions
mhegazycommented, Jul 27, 2018

I think we are just trying to be too clever here. just remove the damn thing 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

These Are The World's Most Dangerous Volcanoes - Time
See some of the world's most dangerous volcanoes, based on their volcanic history, population densities and magma type.
Read more >
International Health Regulations (IHR) - CDC
The International Health Regulations (IHR) 2005 are a legally binding agreement of 196 countries to build the capability to detect and report potential...
Read more >
Protect your PC from potentially unwanted applications
With reputation-based protection Windows users can be better protected from potentially unwanted apps (PUA).
Read more >
Sexually transmitted infections (STIs)
An estimated 296 million people are living with chronic hepatitis B globally. STIs can have serious consequences beyond the immediate impact ...
Read more >
Social media, online gaming and keeping children safe online
Find out what the potential dangers are and how to deal with them to make sure ... Safety tools; Profile/ screen name; Staying...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found