Even if (1) @extends is provided and (2) we're not producing
diagnostics. That's because we need to know whether the extends clause
references an imported alias.
* Change the default type parameter constraint and default to unknown from {}
* Relax unknown checking outside of strictNullChecks a bit
* Increase strictness on index signatures with type `unknown` so inference doesnt change surprisingly
* Remove redundant switch
* Forbid accessing const & let on globalThis
It's just an error; you still get the type of the property.
* Disallow access of blockscoped vars on globalThis
Also change Array, Function, String, et al from `const` to `var` so that
they remain accessible via `globalThis.String`.
* Update baselines after lib.d.ts change
Note especially the change in redefineArray, which is now allowed as
long as you provide a type that is assignable to ArrayConstructor.
* Remove blockscoped vars from typeof globalThis
Unlike forbidding them, this removes the properties entirely.
Unfortunately, this means that accessing these properties is only an
error with noImplicitAny, and that error is quite confusing.
Let's discuss our options. I see 3:
1. Forbid access of block-scoped vars as properties (in all flag
settings), but leave them on the type. Simple to implement.
2. Remove block-scoped vars from the globalThis type. Has the bad
error/flag behaviour described above, but simple to implement.
3. Remove block-scoped vars from the globalThis type. Also, forbid
accessing them by executing another resolveName lookup for failed
property accesses on globalThisSymbol. If the second lookup returns a
blockscoped var, issue an error instead of falling back to the index
signature. This seems too complex to me.
* Update baselines
* Better error for block-scoped usage on globalThis
So that value-space references have as clear an error as type-space
references.
* Update fourslash tests
* Fix semi-colon lint
* Don't copy so much when filtering blockscoped vars
* span on first arg that exceeds arity
* refactor baseline
* handle cases for spread arguments
* refactor + add coverage for tuple spread cases
* create diagnostic on NodeArray of exceeding args
* test function overloading
* Restore original code from bind-toplevel-this
With one or two additional comments
* Working in JS, but the symbol is not right.
Still need to
1. Make it work in Typescript.
2. Add test (and make them work) for the other uses of GlobalThis:
window, globalThis, etc.
* Check in TS also; update some tests
Lots of tests still fail, but all but 1 change so far has been correct.
* Update baselines
A couple of tests still fail and need to be fixed.
* Handle type references to globalThis
The type reference must be `typeof globalThis`. Just `globalThis` will
be treated as a value reference in type position -- an error.
* Restore former behaviour of implicitThis errors
I left the noImplicitThis rule for captured use of global this in an
arrow function, even though technically it isn't `any` any more --
it's typeof globalThis. However, you should still use some other method
to access globals inside an arrow, because captured-global-this is super
confusing there.
* Test values with type globalThis
I ran into a problem with intersecting `Window & typeof globalThis`:
1. This adds a new index signature to Window, which is probably not
desired. In fact, with noImplicitAny, it's not desired on globalThis
either I think.
2. Adding this type requires editing TSJS-lib-generator, not this repo.
So I added the test cases and will probably update them later, when
those two problems are fixed.
* Add esnext declaration for globalThis
* Switch to symbol-based approach
I decided I didn't like the import-type-based approach.
Update baselines to reflect the difference.
* Do not suggest globals for completions at toplevel
* Add tests of element and property access
* Look up globalThis using normal resolution
globalThis is no longer constructed lazily. Its synthetic Identifier
node is also now more realistic.
* Update fourslash tests
* Add missed fourslash test update
* Remove esnext.globalthis.d.ts too
* Add chained globalThis self-lookup test
* Attempt at making globalThis readonly
In progress, had to interrupt for other work.
* Add/update tests
* Addres PR comments:
1. Add parameter to tryGetThisTypeAt to exclude globalThis.
2. Use combined Module flag instead combining them in-place.
3. SymbolDisplay doesn't print 'module globalThis' for this expressions
anymore.