e350c357 (#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`. So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.
Fixes#42350
* @typedef: Improve error spans from declaration emit
This is a proof-of-concept fix. I think it could be expanded for all of
jsdoc, but I only set it up for jsdoc type aliases. It could use a lot
of polish too.
* track error node in isSymbolAccessible instead
* Switch to using enclosingDeclaration
Remove trueErrorNode
* add test of @callback and @enum
* Better error + fix @enum error
Since enums don't have a name property, you *have* to call
`getNameOfDeclaration` to go looking through the AST for one.
* Support Top Level "for await of".
* Add test cases for top level "for await of".
* Apply suggestions from code review
* add test cases
* remove redundant variables
* fix test baselines
* Update diagnostic message and tests
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
* Add support for abstract constructor types
* Add backwards-compatible overloads for creating/updating constructor types
* Reverting use of 'abstract' in lib/es5.d.ts due to eslint issues
* Update baseline due to reverting lib
* Add error for failing to mark an mixin class as abstract
* Fix declaration/quick info for abstract construct signatures
* Support starting and middle rest elements in tuples
* Accept new baselines
* Include all rest arguments in error span
* Accept new baselines
* Fix tests
* Add new tests
* Fix lint errors
* Infer template literal types for template literal expressions
* Update test
* Update another test
* Accept new baselines
* Minor fixes
* Add tests
* Accept new baselines
* Make new TypeFlags internal
* Accept new API baselines
* Ensure template literals assignable to String, Object, {}, etc.
* Add tests
* Less aggressive wildcard check, 'keyof any' constraint for 'infer T' in mapped type constraint position
* Accept new baselines
* Add regression tests
* Allow type-only ImportEqualsDeclarations
* Suppress CJS-in-ESM error when type-only
* Add grammar error on import type in import alias
* Update API baselines
* Fix importsNotUsedAsValues with ImportEqualsDeclarations
* Make bad error talk words more good for Daniel. Fixes#41603
* One more error message baseline update
* Update transformer and emitter
Fixes resolution of export aliases in the postfix-property-access case
of commonjs require:
```js
const { x } = require('./foo').nested
x
```
This program would previously fail if `x` was an export alias.
Fixes#41422
* Support xml namespace prefix for JSX elements and attributes
Just as with the `-` character, `:` is now also treated specially in JSX
element and attribute names, but is only allowed a single time, and not
at the beginning or end of the name, as is specified in the JSX spec.
All tests in jsxInvalidEsprimaTestSuite still fail, but for slightly
different reasons now. Two lines in jsxEsprimaFbTestSuite were
uncommented as they included elements with namespaces, and they now pass
without error.
* Add case for colons at ends of identifier
* Add case for jsx namepsace intrinsics
* Add cases with upcase idents for jsx namespaces
* Add case for jsx namespaces with react option
* Always consider jsx names with colon to be intrinsics
* Adjust comment about chars valid in jsx names but not js idents
* Fix minor typo in namespace prefix test case variable name
* Remove misleading comments on isUnhyphenatedJsxName
```js
const x = require('./foo').y
```
was incorrectly using the unmangled require path as the temp name in
emit:
```
import ./foo_1 = require('./foo')
import x = ./foo_1.y
```
It now uses the imported identifier:
```
import x_1 = require('./foo')
import x = x_1.y
```
Discovered while fixing #37832
* fix(lib): SharedArrayBuffer does not have a `length` field
* Revert formatting change.
* test: add tests for SharedArrayBuffer.length
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* Fix reference types in @typedef
Previously this code path was broken and untested. Fortunately the fix
is simple.
* add test case from #40234
* update baselines
* Ensure whitespace jsx elements are not counted when determining if a jsx child is the only child
* Use filtered children count for deciding constructor used
* Accept updated baselines post-merge
* Fix noUncheckedIndexedAccess for tuple rest elements
* Defer inclusion of undefined for generic indexed access types
* Create separate IndexedAccessTypes depending on whether --noUncheckedIndexedAccess applies
* Undo accidental export
* Parenthesize for clearer precedence
* Fix default-property-assignment decls+prototype property decls
The check in getAssignedClassSymbol forgot to allow for default-property
assignment declarations, in part because it wasn't using a utility
function to do so.
* small cleanup
* make allowDeclaration parameter required
When a union is spread into a union, the sizes are multiplied,
potentially resulting in an enormous union (especially if there are
repeated spreads). This check detects cases that used to run out of
memory.
Fixes#40754
* Allow pattern literal types like `http://${string}` to exist and be reasoned about
* Allow bigint, number, null, and undefined in template holes
* Add test of the trivia case
* Handle `any` in template holes, add assignability rules for template -> template relations
* Explicitly test concatenated patterns
* PR Feedback
* Fix error on duplicate commonjs exports
Previously, the code missed setting the parent pointer for the lhs
access expression.
Also add declaration emit of element access expressions, missed in my
previous PR.
* Switch to excludes=None, add test case
CommonJS exports have None excludes, but still have an error issued by
the checker. This is the previous behaviour even though it would be nice
to add some exclusions.
* Initial implementation + tests
* linty
* Support destructuring declarations and assignments
* lint
* Fix destructuring assignment and element access into known properties
* Update baselines
* Rename flag to unUncheckedIndexedAccess
* Add test for unique symbol indexing
* Fix flag order in baselines
Co-authored-by: Andrew Branch <andrew@wheream.io>
* Adds support for declaring the bundled name of a dts module export
Co-authored-by: Wesley Wigham <wwigham@gmail.com>
* Adds baselines
* Update the tests
* Try to reduce the scope of the bundledPackageName error
* Use the flag in more baselines
* Get it green
* More tests
* Handle more feedback
* More test cleanup
* Set the moduleResolution for the tsconfigs
Co-authored-by: Wesley Wigham <wwigham@gmail.com>
* Use ad-hoc code for nested destructuring in require
Nested destructuring doesn't really map to ES imports:
```js
const { utils: { nub, intercalate } } = require('./monopackage')
```
Previously, isRequireVariableDeclaration walked up binding elements
until it reached a variable declaration. This change instead only walks
up one binding element and stops. Then it's not bound as an alias and
uses the checker-only code to produce types for the nested-imported
identifiers.
Fixes#40143
* revert binder formatting change
* Alias for `module.exports.x = x`
This fixes#40155 in a surprisingly small amount of code.
* Treat any aliasable expression as an alias
* test internal references to exported class
* Initial implementation of string template types
* Accept new API baselines
* Accept new baselines
* Unified checking for large cross product union types
* Accept new baselines
* Ensure errors from union type resolution are reported
* Accept new baselines
* Compute constraints for string template types
* Support `as T` clause in mapped types
* Accept new API baselines
* Add missing semicolon
* Add checking of `as T` clauses
* Support casing modifiers in string template types
* Accept new baselines
* Bump keyword maximum length
* fix anders
* Revert "fix anders"
This reverts commit b3178d4618.
* Properly handle 'as T' clause with keyof for mapped type
* Fix lint error
* Single character inferences and anchored end span matching
* Fewer array copy operations in template literal type resolution
* Handle cases where 'as T' maps multiple properties onto one
* Fix lint error
* Store key type instead of type mapper in MappedSymbol
* No constraint on `in T` type when `as N` clause present
* Rename from TemplateType to TemplateLiteralType
* Accept new API baselines
* Add tests
* Accept new baselines
* Address CR feedback
* Accept new API baselines
Co-authored-by: Erich Gamma <egamma@microsoft.com>
* Add see tag parser
* add baseline
* fix symbol resolve
* add more case
* fix unittests
* improve tests and parser
* accept baseline
* Adopt package-lock.json and npm ci
* Add a workflow to update package-lock.json daily
* Git ignore package-lock.json and forcibly update in workflow
* Update bot email address
* Delete extra npm update
* Update package-lock.json
* Add compactDisplay and signDisplay to NumberFormatOptions (#40039)
* Fix typo in (Readonly)Set.keys comment (fixes#40164) (#40176)
* fix(26325): use a unique name for reserved words in 'constructor like' function name (#39684)
* fix(25770): add diagnostic message for the possible mapped type used as an index (#39973)
* fix(31046): add new diagnostic message for incompatible constructor signature (#40073)
* Update package-lock.json
* Update package-lock.json
* Add rename support
* Accpet baseline
* wip
* fix anders
* Revert "fix anders"
This reverts commit b3178d4618.
* Fix call hierarchy item serialization and server tests (#40348)
* Avoid error
* accept baseline
* Add more tests
* Add signature name resolve
Co-authored-by: Andrew Casey <andrew.casey@microsoft.com>
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
Co-authored-by: Neil Kistner <neil.kistner@gmail.com>
Co-authored-by: cherryblossom000 <31467609+cherryblossom000@users.noreply.github.com>
Co-authored-by: Alexander T <alexander.tarasyuk@outlook.com>
Co-authored-by: Erich Gamma <egamma@microsoft.com>
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
* Consistently error when rest element isn't last in tuple type
* Add regression test
* Accept new baselines
* Stricter circular recursion check in type inference
* Revert "Stricter circular recursion check in type inference"
This reverts commit 80e6df6230.
* Revert "Accept new baselines"
This reverts commit 355706dadc.
* Accept new baselines
* Passing --checkJs always sets --allowJS
Even if you have `"allowJs": false`. This is not a useful combination.
Changing this makes the compiler more friendly and easier to describe.
* only set allowjs if not explicitly set
* remove stray newline
* restore bad config error
* use an accessor function instead
* Fix crash intersecting dynamic import w/esModuleInterop
The dynamic import shim creates a symbol without some properties that
the intersection-creating code assumes are present as of #38673.
This PR adds the smallest possible set of properties to avoid the crash.
I'm not sure what others would be good to add.
* Use symbol's declarations instead
* Fix getResolvedMembersOrExportsOfSymbol instead
* comment from code review
The commonjs-specific code for resolving access expressions on `require`
assumes a fake commonjs export. For real exports, it needs to call
resolveSymbol since it's outside the normal alias-resolving
infrastructure.
From the user tests:
```js
const x = require('y').z.ka
```
would cause the crash because I forgot to call
getLeftMmostPropertyAccessExpression in one place.
Note that this doesn't fix the alias, it just stops the crash.
* First attempt at aliases for require
* test+initial support for const x=require
* 1st round of baseline improvements
* 2nd round of baseline updates
* support property access after require
* check @type tag on require
* forbid expando missing namespaces on aliases
taken from #39558 as soon as it was created
* accept error baselines that are good, actually
* Scribbling on d.ts emit code
* use getSpecifierForModuleSymbol
* hideous hack for module.exports of aliases
* Fix module.exports.x --> export list emit
* fix isLocalImport predicate
* require only creates aliases in JS
* re-handle json imports
* update fourslash baseline
* Cleanup in the checker
1. Simplify alias resolution.
2. Simplify variable-like checking.
3. Make binding skip require calls with type tags -- they fall back to
the old require-call code and then check from there.
I haven't started on the declaration emit code since I don't know what
is going on there nearly as well.
* Function for getting module name from require call
* First round of cleanup plus a new test
Found one missing feature, not sure it's worth adding.
* more small cleanup
* more cleanup, including lint
* use trackSymbol, not serializeTypeForDeclaration
* Code review comments, plus remove unneeded code
Ad-hoc type reference resolution for `require` isn't needed anymore.
* find all refs works
* remove old ad-hoc code
* make it clear that old behaviour is not that correct
* update api baselines
* remove outdated comment
* PR feedback
1. Fix indentation
2. Add comment for exported JSON emit
3. Add test case for nested-namespace exports.
* add a fail-case test (which passes!)
* Bind alias ThisProperty assignment declarations
This is a quick prototype that does the wrong thing at the wrong time
with the wrong technique.
* Preliminary checker handling for aliases
Duplicative and untested, but I think I updated all the places that need
updating.
* new is error; old one should not have been removed
* I don't even know what's happening with this test
* cleanup and testing in the checker
* binder: use lookupSymbolForNameWorker instead of mutable
This should have about the same behaviour and is much easier to
understand.
Also refactor common code a bit.
* Shorter name of lookupSymbolForName
Once upon a time there was a parent/worker function, but now it's just a
single function again. No need for the -Worker suffix.
* remove oodate comment
* fix switch-case-break lint
* Refactor and move functions
* Rename and improve type of getContextualTypeForAssignmentDeclaration
* Fix this parameter emit for JSDocFunction types
Previously, parameters with names that were not `new` were treated like
rest parameters. This is incorrect: parameters with the name `this`
should emit a `this` parameter.
Fixes#38550
* ❤️ quote style
Previously, getObjectTypeInstantiation had special-case code to look up
type parameters for `@param` as if they were in the parameter location.
This should occur in the main lookup loop of `getOuterTypeParameters`,
however. The current code only runs once, which is not sufficient, and
it also jumps to the parameter for any type contained in a `@param`,
which skips type parameters that occur in the tag itself.
* Type `this` in more constructor functions
Previously, `this: this` in constructor functions only when there was
an explicit `@constructor` tag on the function. Now, `this: this` for
any function that's known to be a constructor function.
This improves completions inside constructor functions; also note that
previously the compiler *did* type `this: this` inside methods of constructor
functions, so this fix makes us more consistent. This is reflected in
the large number of baselines that improve.
The fix is a simple switch to `isJSConstructor`, which is the standard
way to detect constructor functions. I'm not sure why the original PR
didn't use this method.
I remember discussing this limitation in the original bug, #25979, and
I guess I decided that it made sense. But I was heavily primed by the bug's
framing of the problem in terms of `noImplicitThis`, which *should*
require an explicit `@constructor` tag.
With better typing comes better detection of `@readonly` assignment; I
had to fix the readonly detection code to use `isJSConstructor` as well.
* Remove `Add @class tag` fix for noImplicitThis.
The new rules mean that it never applies. It's possible that it should
apply to functions like
```js
function f() {
this.init()
}
```
In which `init` is never defined, but I think this program is incomplete
enough that not offering the fix is fine.
* Fix precedence of `@this`
Previously, both `@class` and `@this` in a jsdoc would cause the `@this`
annotation to be ignored. This became a worse problem with this PR,
because `this` is correctly typed even without the annotation.
This commit makes sure that `@this` is checked first and used if
present.
* Parse *= separately in types
Previously, when the scanner produced `*=` as a single token, the type
parser ran special-case code to produce an "optional all type", which
only makes sense when the `=` really should be attached to the `*`. This
is often not the case.
The correct solution, which I missed when I first wrote this code, is to
have the scanner go back and produce a separate `=` token, which is what
this PR does.
* add test from #38551
* we ❤️ semicolons
Previously, property assignments with `void 0` initialisers were treated
like any other values. But this causes us to choke when checking our own
commonjs emit. This is something that happens by mistake a fair amount,
so this PR goes back to treating these assignments as normal
assignments.
This should allow us to check our own emit in loose cases without
harming other code bases, since `void 0` is rarely written by hand.
Note that other errors still happen: noImplicitAny forbids
accessing undeclared properties on object literals, and strictNullChecks
forbids assigning `undefined` to properties with a different type.
However, this change is enough to unblock compilation with
`strictNullChecks: false`.
* Initial implementation of variadic tuple types
* Accept new baselines
* Handle variadic elements in tuple type inference
* Special case inference between tuples with matching structure
* Restore check that rest element is last element
* Handle variadic tuples in relationship checking
* Accept new baselines
* Infer readonly constraints when inferring from readonly tuples
* Fix lint issues
* T assignable to readonly [...T] and [...T] assignable to T
* Consistent tuple normalization
* Create variadic tuple types from array literal expressions
* Accept new baselines
* Array literals have tuple types when contextual type is readonly
* Accept new baselines
* Optional elements before required elements become required elements
* Update logic for rest parameters and spread arguments
* Revert special case of contextual readonly array type
* Accept new baselines
* Fix lint issue
* Switch entirely to createTupleType based on element flags
* Don't infer readonly tuple types when inferring to variadic elements
* Handle mapped types applied to generic tuple types
* Handle constraint of indexed access type with generic tuple type
* Accept new baselines
* Address CR feedback
* Simplify indexed access types involving generic tuple types
* Propagate checkMode into getSpreadArgumentType
* Guard against missing globalArrayType
* Inference to [...T, ...U] based on implied arity of T
* Accept new baselines
* Add tests
* Emit .d.ts from tests
* Address CR feedback
Outside of JSDoc comments, postfix-? is parsed at lower precedence than
the `?` of conditional types, and a postfix-? inside a tuple type
results in the type being marked optional.
This PR changes JSDoc parsing to behave the same way, which means that
1. Conditional types are allowed in JSDoc. Fixes#37166.
2. Tuple types' postfix-? syntax is interpreted correctly in JSDoc.
Fixes#38747.
The breaking change is that a postfix-? type followed by another postfix type,
like `[]` or `!`, is parsed as a conditional type. [Postfix-? is not
common](https://github.com/microsoft/TypeScript/issues/37166#issuecomment-612274456),
so this is an acceptable breaking change.
A postfix-? type `T?` is still parsed everywhere else and treated as `T | null`.