* Cache accessibe symbol chains, type parameter name generation
* Move signature declaration helper length approximation to start of function
* Add node result caching internal to `typeToTypeNodeHelper`
* Suggestion from PR
* Improve errors for incorrectly nested export default
The compiler and services don't handle incorrectly nested
`export default` well right now:
```ts
export = (x,y) => {
export default { }
}
```
Asking for document highlights, find all references or quick info on
'export' or 'default' cause a crash. After the crash is fixed, the error
message is confusing and wrong: "An export assignment cannot be used outside a module."
This PR:
1. Skips document highlights for incorrectly nested export default.
2. Skips find all refs for incorrectly nested export default.
3. Switches the fallback binding for incorrectly nested export default
from Alias to Property. Neither is correct, but Property doesn't cause a
crash in alias resolution.
4. Improves the error message to reflect a post-ES module world, which
has export default and 'module' means 'ES module', not 'namespace'.
Fixes#40082 and the related bugs mentioned above.
* address PR comments
PR #42556 was a nice optimization that dramatically sped up comparisons of discriminated unions. Unfortunately, the cost of determining whether a union is discriminated can be prohibitively high. In particular, an internal team with a very large repo saw their type count double and their memory usage increase from 6GB to 9GB, breaking their build. This changes splits the difference by not trying to compute the property types of intersection types - a notoriously slow operation.
* Allow filterType to consider union constraints of non-union types when determining never-ness
* Move impl to callback
* Baseline change in narrowing behavior into test, fix post-LKG build
* Test where relative import isnt ideal in the declaration emit
* use project relative preference for declaration emit
Fixes#39117
* Fix incorrect path matching when calculating module specifier
* Use correct baseUrl for the module specifier
Previously, getExternalModuleMember passed through its received value of
`dontResolveAlias` to every function that accepted it. That includes (1)
resolution of the module symbol and (2) resolution of the module
specifier. However, in TS, the module symbol is never an alias anyway, so
dontResolveAlias doesn't make a difference. In JS, the module symbol
*can* be an alias, and it should always be resolved. That's what this PR
does.
Fixes#43713
* Scribbles + tests
The second test actually requires node types
* Basically working
The two simple fixes, in arity error reporting, are in, and the
simplification of arity error reporting is half-done. I haven't started
on any improvements to call assignability.
* trim out too-real test case
* Finish cleanup
And reword error a little.
* Simplify and reword spread errors
* handle spreads first
* update baselines
* Address PR comments
* Allow `override` as parameter property
* Update other baseline
* Add test for override on normal parameter
* Copy typo fix
* Update baselines
* Update API baseline
* Relate non-augmenting array subtypes without resorting to structural comparison
* Fix lint
* Generalize performance enhancement
* Cache results, feed through via getNormalizedType to remove error intermediates
* Use newly freed up object flags to limit member setting, fix crash with those object flags
* Move flags because there is no TypeFlags.Reference 🤦
* Fix completions of exports elsewhere in same file
* Undo messing up JSDoc-annotated module.exports assignments
* Add other failing contextual type test
* Rearrange contextual type logic for special assignments
* Rename helper function
This diff extends the types checked by
discriminateContextualTypeByObjectMembers and
discriminateContextualTypeByJSXAttributes to also include any optional
components in the type union.
fixes#41759 although it doesn't address the better error reporting for
their last repro, which I'm not sure how to address.
* Completion list for type literals in type arguments
* Add tests
* Refactor for better readability
* - Support non-identifier keys
- Move main logic onto tryGetGlobalSymbols function
* Instantiate getter when infering setter parameter value
* Use esnext on tests
* Instantiate for JsDoc and getter from body
* PR comments
* Updated baseline
* Use faster, stricter prop type comparison when merging props in union prop creation
* Be better at determining this usage in methods, accept baselines
* Small style change
* Consider identical instances of the same symbol equivalent when creating union and intersection properties
* Also copy over mapper and type (if available) on cloned symbols
* Editorial feedback
* Test + Initial scribbles
The test is pretty good, the scribbles are actually cleanup from last
PR, although they break some tests.
* undo scribbles, add nonworking class-hack
* Ad-hoc name resolution for @link and @see
Turns out that you can't reuse check* functions if you want to retrieve
all meanings of a reference.
* fix failing test
* inline hapax function
* Fix find-all-refs baseline print
* Try to resolve C.m as static first
* Add interface tests
Co-authored-by: Andrew Branch <andrew@wheream.io>
* Ignore object types in intersections with primitive types
* Add regression test
* Also handle instantiable types constrained to object types
* Add another test
* Add ignoreObjects optional parameter to getTypeFacts
* If target:esnext,then useDefineForClassFields: true will now be the default.
* Added error if a private identifier is used in a static a initializer if target:ESNext and useDefineForClassFields:false.
* Added test for new useDefineForClassFields default and error message.
* Fixed tests after changing the default of useDefineForClassFields to true for target esnext
* Fixed code review suggestions.
* Updated error message.
* Added missing static check for the containing property. Fixed other code review issues.
* Allow redeclaring CommonJS alias with initial undefined
This allows us to read our own output, plus the times when people
manually write exactly the same pattern.
Fixes#40555
* Use control flow to type commonjs exports
1. Could probably use a *lot* more tests.
2. getTypeOfAlias redoes some work from resolveAlias because it needs to
not resolve the alias completely, just to its export.
* fix lint, improve jsdoc
* Add tests, improve+fix control flow
1. Update the module.exports test to match the exports ones.
2. Add a test of evolving commonjs type.
3. Add a test of assignment as last statement.
(1) exposed a bug that required a better synthetic reference. (3)
exposed a bug that was most easily fixed by giving source files a
`endFlowNode` like functions and setting it in the binder.
* fix lint
* Fix getRecursionIdentity, undo changes from #43435 (but keep tests)
* Remove test that takes excessively long to run
* Accept new baselines
* Fix formatting
* Add regression tests
* Reinstate test
* Do not covariantly mix in constraints from contravarrying positions
* Exclude keyof from constraint variance tracking
* Extra test case
* Always subtitute on type parameter types
* WIP
* WIP
* Get completion details working
* Start unifying eager and lazy auto imports
* Fix export=
* Fix completion details for totally misspelled names
* Almost fixed duplication...
* Fix remaining completion tests
* Refactor to support multiple origins for same symbol
* Make import fixes make slightly more sense
* Add cache back in
* Set insertText based on import kind
* Update API baselines
* Add semicolons, snippet support, and sourceDisplay
* Add some tests
* Update baselines
* Fix pattern ambient modules appearing in auto imports
* Fix tests
* Remove commented code
* Switch to valueDeclaration for getting module source file
* Small optimizations
* Cache module specifiers / importableness and export map separately
* Fix and test cache invalidation logic
* Update API baselines
* Add separate user preference for snippet-formatted completions
* Require first character to match when resolving module specifiers
* Fix AutoImportProvider export map cache invalidation
* Really fix auto import provider export map invalidation
* Update test added in master
* Use logical or assignment
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* Simply conditional by reversing
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* When file is deleted need to marked correctly in the project as removed file
* Simplify hasAddedOrRemovedSymlinks with cherry-picked fix
* Ensure replacement range is on one line
* Update baselines
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
* Added support for private identifier methods.
* Added tests for private methods.
* Added check to only not allow private name method signatures in anything except classes.
Changes objects literal checking to not bail on first private name found in object literal.
* Added private accessors tests
* Transform private methods
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Rename shouldTransformPrivateFields
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Use a single WeakSet for brand-check
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add a test for using private methods in static field initializers
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add breaking checker test
Private methods inside class expressions should not error.
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add to instances once per-instance
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: evaluate receiver and rhs expressions before throwing on readonly assignment
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add a test for evaluating rhs before readonly assignment
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Transpile private accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: handle readonly/writeonly accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for private setter without a getter
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: getAllUnscopedEmitHelpers
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: better handling of duplicate names
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Fixed wrong error message for private methods in class expressions.
* change error message
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for async private methods with a higher target
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: setter assignment returns rhs value
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for setter assignment return value
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: handle duplicate accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add tests for duplicate accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* docs: add missing parameter docs
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Fixed failing test.
* baseline-accept: ordering changes
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: attach weakSetName to property declaration
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for nested private methods
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test with any
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Added support for static private fields accessors and methods.
* Added error message for private identifiers used with static decorators. There is no spec to go with this behavior as of yet.
* Fixed emit static bug that used private names outside of classes for initialization in esnext. Fixed issue where nested privates produce incorrect brand check.
* Added tests for private static fields methods and accessors.
* Fixed error messages and tests after merge.
* Accept new baseline.
* Improved duplicate identifier checks for static private class elements.
* Added error when using initializers with private static fields when useDefineForClassFields is not specified and target is esnext.
* Fixed code review issues.
* Removed semantically wrong emit on `useDefineForClassFields:true` with `target:esnext`
* Changed emit for uninitialized private static fields.
* Added runtime error in helper if a static private field is accessed before it was declared.
* Fixed code review comments for private identifier static class elements.
* add debug.assertNever for unknown node type (#53)
* Fixed code review issues.
* Fixed code review issues for private class elements.
* Fixes class shadowing when checking access to a private static class element.
* fix private methods/accessors in class expr inside a loop
* collapse switch case
* fix class name
* simplify getPrivateMethodsAndAccessors
* remove findPreviousAccessorInfo
* lazily create weakSetName identifier
* do not allocate a node if not needed in visitMehodDeclaration (#55)
* Removed all the emit helpers for private identifier methods accessors and modified the existing helpers for get and set fields to do the same job.
* Simplified emit for private identifier class elements.
* do not clone the receiver (#57)
* leave bad code in for #constructor and duplicate private names (#58)
* Added check for WeakSet collision.
* Added error for using a set only accessor.
* update keyof tests and ?? (#62)
* replace ?? with ||
* update keyof tests
* fix emit helpers comments
* produce an error if private field helpers are not up to date
* add tests
* fix setter-only compound assignment
* fix tests
* fix duplicated trailing comments (#64)
* clear receiver pos and setTextRange on helper calls
Co-authored-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Revert "Revert "Editor support for link tag (#41877)" (#43302)"
This reverts commit 451d4354b9.
* Fix parsing @link at end of comment
* Parse comments as string when no @link occurs
* fix lint
* Narrow type variables with union constraints when merited by contextual type
* Narrow generics with union type constraints as indicated by contextual type
* Accept new baselines
* Add tests
* Fix circularity for JSX elements
* Remove unnecessary isConstraintPosition information from flow cache key
* Update comment
* Add additional tests
* Rename to getNarrowableTypeForReference, remove getConstraintForLocation
* Add comment
* Fix removal of undefined in destructurings with initializers
* Use getContextFreeTypeOfExpression in discriminateContextualTypeByObjectMembers
* In obj[x], use constraint of obj's type only when x's type is non-generic
* Add comment
* Initial scribbles
* Compiles but provides spans instead of location pairs
Probably need to fork the services/server types and provide a conversion
with Session.toFileSpan. Not sure where to put the conversion.
* Switch to DocumentSpan
In theory this is already better supported, but not sure practise bears
that out.
* Builds w/protocol types + conversions
* cleanup:better names and scrub TODOs
* fix test harness too
* Misc
1. Simplify protocol after talking to @mjbvz.
2. Add more tests.
3. Initial notes about where to add parsing.
* Parse and store links in the compiler
The text of the link is still stored in the comment text, but that's now
kept in an object instead of just a string. Each link has the parse for
the entity reference, if there is one.
Needs lots more tests -- this just makes all the existing jsdoc tests
pass.
* more tests and some fixes
* Fix other failing tests
* fix bad merge
* polish parser
* improve names and array types
* slight tweaks
* remove some done TODOs
* more tests + resulting fixes
* add+fix cross-module tests
* Support `@see {@link`
Plus find-all-refs support equivalent to @see's.
* add server test
* Make comments actually part of the AST
* Add span for link.name in language service/protocol
* Make checker optional in getJSDocTags
Also change to JSDocCommentText from JSDocCommentComment
* Use getTokenValue instead of getTokenText
Measure twice, slice once
* Add missing support for top-level links
The language service and protocol were missing support for top-level
links. This commit adds that plumbing.
* add string back to comment type in node constructors
* Full parse of link tags and jsdoc comment text
- Doesn't pass fourslash yet, I'm going to switch to baselines for
failures there.
- Still needs some work on the protocol to convert file+offset to
file+line+offset.
* fix lint
* Fix missing newlines in inferFromUsage codefix
* Parse jsdoc comments as text node/link array
And switch to line+character offsets in the protocol
* Fix fourslash tests
Mostly ones that can't be baselined, but I switched a couple more over
to baselines
* Improve types and documentation
* Test+fix @link emit, scrub other TODOs
* update API baselines
* test that goto-def works with @link
* Split link displaypart into 3
One for link prefix and suffix, one for link name, and one for link
text.
* update baselines
* Provide JSDocTagInfo.text: string to full clients by default
Instead of upgrading them to displayparts.
* Real server tests
* Disambiguate {@link} and @param x {type}
They are ambiguous; previously the parser preferred the type
interpretation, but will now look ahead and parse links instead when the
prefix is `{@link`.
* Add explanatory comment in test
* fix location in richResponse in protocol
* update API baseline
* Address PR comments
1. Add a cross-file goto-def test.
2. Switch from per-message args to UserPreference.
* use arraysEqual from core
* Finally add that missing relationship allowing a type to be assignable to both branches of a conditional
* Explicitly write out Ternary.Maybe
* Add slightly modified example from #25413
* fix sick sentence
* Loosen check to skip false branch constraint check to consider `infer` parameters as always satisfied in the extends clause
* Simplify things a bit, only instantiate once
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Fix property name bindings for class expr in loops
* Fix block-scope capturing with prop initializers
Co-authored-by: Joey Watts <joey.watts.96@gmail.com>
This was caused by the fact that getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull) will return never both if resultType was already never and if resultType does not contain undefined or null. In the latter case returning the declaring type is correct, in the former case this causes something narrowed to never to still be typed as the original declared type.
* About halfway through the checker
I'm going to merge with master to avoid clashing with the declaration
fix.
* Add undefined to Symbol.valueDeclaration
Also add undefined to a number of utility functions that have always
accepted it, but never added it to their type.
* Fix lint from code review
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* remove obsoleted fix from inferFromUsage
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* Add undefined to Symbol.declarations' type
Symbol.declarations now has type `Declaration[] | undefined`.
I made a mistake somewhere in the checker related to JS checking, so
there are quite a few test failures right now.
* undo clever change to getDeclaringConstructor
* Address PR comments
1. More early-returns.
2. More line breaks.
* Add 'data' property to completion entry for better cooperation between completions and completion details
* Add doc comment
* Update API baselines
* Add server test
* Test session’s Full result
* Fix tests
* stableSort to fix server fourslash test
* Explicit verification of data parameter
* No array literal subtype reduction when contextual type is present
* Accept new baselines
* Fast path in relations and filtering of pure discriminated union types
* Create maps for mixed unions, but not for small or primitive only unions
* Create many-to-many mapping with certain limits, also use in CFA
* Use constituent maps in CFA for switch statements, cleanup, add comments
* Revert change to apparent contextual type / better criteria for map eligibility
* Deduplicate array literal element types
* Accept new baselines
* Filter in false case only when discriminant property has unit type
* Only subtype reduce unions with less than 100 distinct types
* Accept new baselines
* Caching and quick discriminant checks in subtype reduction
* Accept new baselines
* Remove deduplication logic now that subtype reduction was optimized
* Only enable special assignability rule on string index signatures to 'any'.
* Accepted baselines.
* Added test.
* Accepted baselines.
* Renamed test files.
* Add non-erroring version of bclas'subClassThisTypeAssignable01.ts'
* Accepted baselines.
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
* Fix: checkAliasSymbol crash when checking for @deprecated
It's possible that we shouldn't be creating symbol with no declarations
from non-homomorphic mapped types, but for 4.2, the right fix is to make
the @deprecated-check in checkAliasSymbol ensure that
target.declarations is defined.
* Add bug number and accept baselines
* When structurally comparing similar types, check if we are already in the middle of a more general comparison of those same types
* Do the same, but with only string manipulations
* Eliminate well-known symbols in the checker: 2021 edition
* Actually update the lib text to say unique symbol, too (this is unneeded with compat code in place, but this makes goto-def make more sense)
* Add test showing mismatched symbol constructor type interop
* Add more test cases for some other related issues this fixes
* Revert computed name change
* Style comments
* When noImplicitAny is set, combine multiple contextual overloads into a single signature, rather than producing `any` and an error
* Amalgamate intersection composite signature return types as intersections, rather than the prior exclusively union behavior
* Add another example from an issue, albeit slightly modified
* Fix newlines, add test from DT
* Interior remodelling
* Improve @template lookup and resilience
1. @template parsing may produce a template tag with a type parameter
whose name is the missing identifier. These tags should be skipped
in the checker because they receive an error in the parser.
2. The fix in #37819 was incorrect; there's no such thing as a type
parameter declared on a variable declaration. Instead, there needs to be a type
parameter declared on a jsdoc comment, because that's the scope for tags
like `@return` and `@typedef`.
There are 3 tests because either fix (1) and (2) fix the first test's
failure, but both are required to fix the last two tests' failures.
* remove containsParseError call
* Specified error message for iterating known array types without --downlevelIteration
* Added extra target info to diagnostic
* NodeList too, a classic
* PR feedback: invert to allowsStrings; required param
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Change variable name AllowQualifedNameInPlaceOfIdentifier to AllowQualifiedNameInPlaceOfIdentifier
* Change deleting AllowQualifedNameInPlaceOfIdentifier to deprecating it instead.
* Fix failing tests
* Replace old value
* No did-you-mean-to-call error on casts
I chose to do the ad-hoc check rather than yet another tree walk.
1. It's faster to run and easier to read.
2. This error came from looking at real code. It happened twice, so I
think the best estimate for other uses that happened zero times is in
fact zero.
3. I couldn't think of other places to put the cast, given the
restrictions on `testedNode` just before the new code.
* Skip parentheses
I chose to do the ad-hoc check rather than yet another tree walk.
1. It's faster to run and easier to read.
2. This error came from looking at real code. It happened twice, so I
think the best estimate for other uses that happened zero times is in
fact zero.
3. I couldn't think of other places to put the cast, given the
restrictions on `testedNode` just before the new code.
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
The original error message on the last line I have added to in
functionParameterArityMismatch.ts was
No overload expects 5 arguments, but overloads do exist that expect
either 4 or Infinity arguments.
even if we do not define a function that takes Infinity arguments.
This PR changes it to this:
Expected 0-6 arguments, but got 5 or more.
I feel it is still a bit strange but much more understandable.
Fixes#42418
Make `tracing` either `undefined` or the same namespace as before.
Switching all calls to `tracing?.___` means that there is no cost for
a call or the arguments when tracing is not used. Comparing two runs
without tracing (27 runs, drop 5+5, avg rest) I get:
master:
42.59s user 1.00s system 165% cpu 26.372 total
changed:
42.01s user 0.982 system 165% cpu 26.039 total
(Makes it all private, so no api changes.)
* Commonjs module:create synthetic exports symbol
Previously, the `module` identifier in commonjs modules got a synthetic
type with a single property `exports`. The exports property reused the
file's symbol, which, for a module file, gives the correct exported
properties.
However, the name of this symbol was still the filename of the file, not
`exports`. This PR creates a synthetic symbol for `exports` by copying
in a similar way to esModuleInterop's `default` symbol in
`resolveESModuleSymbol` (although the intent there is to strip off
signatures from the symbol).
* correct parent of synthetic symbol
* Exclude primitive types from union subtype reduction in most cases
* Accept new baselines
* Minor fixes
* Less aggressive checking of assertion function calls that don't affect control flow
* Accept new baselines
* @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>
* fixesmicrosoft/TypeScript#41286
* Added period to end of deprecation message
* Search Symbol.declarations for deprecated tag instead of Symbol.valueDeclaration
* renamed arg0 to deprecatedEntity, narrowed param type
* Added different deprecation message if signature is available
* address PR comments
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Add --force to npm install script for user tests
* Migrate prettier to docker
* Fix vscode Dockerfile
* Fix stack space issue in isJSLiteralType
* Use --legacy-peer-deps based on npm version
* Fix xterm.js Dockerfile
* Add tests for "Cannot find name 'global'. Did you mean 'global'?"
* Fix "Cannot find name 'global'. Did you mean 'global'?"
* Add an additional test case for spelling suggestions of "global".
* Name the boolean for suggestions being global scope augmentations.
* chore: failing test for const enums and isolatedModules
* fix: const enums + isolatedModules emit invalid code
In `isolatedModules` mode, the compiler does not inline const enums,
but also decides not to `import` them, leaving invalid code that
throws a `ReferenceError` at runtime.
This code:
```
import { SomeEnum } from './bar';
sink(SomeEnum.VALUE);
```
..should compile to either:
```
var { SomeEnum } = require('./bar');
sink(SomeEnum.VALUE);
```
..or (with const enum inlining):
```
sink(1 /* VALUE */);
```
..but actually compiles to:
```
sink(SomeEnum.VALUE);
```
..with no imports, which throws a ReferenceError at runtime.
---
The compiler has already realised that the symbol is a referenced const
enum, it just doesn't use this information when it comes to deciding
whether to emit an import. This commit additionally checks that
information, if we are compiling in isolatedModules mode.
---
In my opinion, this is not the correct fix, but it is the simplest. In
`isolatedModules` mode, `const enum` should probably be a compile error
(because there are no benefits and the complexity is high, and,
apparently, buggy). If not, the compiler should not be checking whether
something is a const enum, and should just be treating it as a regular
enum, and checking as if it was?
Fixes#40499.
* chore: extra test for type-only
* feat: explicitly ban --isolatedModules --preserveConstEnums false
* feat: isolatedModules implies preserveConstEnum
* Update src/compiler/diagnosticMessages.json
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
* chore: compiler test for argument incompatibility
* Add and fix test for namespace import of const enum
* Fix additional bug with reexport of const-enum-only module
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
Co-authored-by: Andrew Branch <andrew@wheream.io>
hasNonBindableDynamicName
1. Has 'non' in the name, and is only ever used negated.
2. Is true for a case that's not reflected correctly in the name -- it's
true for non-dynamic names as well.
I considered hasEarlyOrLateBindableName, but decided to use
hasBindableName for now.
* 'in' should not operate on primitive types
* accept baselines of failing tests
* review
* update error message
* check if constraint of right type is assignable to a non primitive or instantiable non primitive
* do not throw errors where narrowing is impossible
* accept baselines
* fix test case failures
* Add more accurate comment discussion and document failing edge case in test
* Update baselines
Co-authored-by: Jonas Hübotter <jonas.huebotter@gmail.com>
* New aliases for type alias instantiations
* New aliases for conditional, mapped, and anonymous object type instantiations
* Accept new baselines
* Fix issues with re-aliasing
* Accept new baselines
* Create separate types for equivalent aliased unions
* Accept new baselines
* Preserve original types for union types
* Accept new baselines
* Preserve intersection origin for union types
* Accept new baselines
* Accept new baselines
* Preserve aliases during relationship checks
* Accept new baselines
* Preserve aliases for intersection and indexed access types
* Accept new baselines
* Compute intersection-of-unions cross product without recursion
* Accept new baselines
* Use denormalized type objects for origin / support 'keyof' origins
* Accept new baselines
* Fix fourslash test
* Recursively extract named union types
* Accept new baselines
* Map on union origin in mapType to better preserve aliases and origins
* Remove redundant call
* Accept new baselines
* Revert back to declared type when branches produce equivalent union
* Accept new baselines
* Don't include denormal origin types in regular type statistics
* Fix issue with unions not being marked primitive-only
* Allow new alias to be associated with type alias instantiation
* Accept new baselines
* Revert "Accept new baselines"
This reverts commit 4507270cc1.
* Revert "Allow new alias to be associated with type alias instantiation"
This reverts commit 2c2d06dfe1.
* Test case where the wrong path is emitted
* If import is used in the file, prefer that import specifier over calculating new one
Fixes#39117
* Update Baselines and/or Applied Lint Fixes
* When non-relative path is used as user preference, ignore relative paths even if they are from the existing file
* Fix test
* Add comment
Co-authored-by: TypeScript Bot <typescriptbot@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
Previously, the error span was too large on @type errors on functions
when the type was not a function. The span covered the entire tag. This
PR changes the error node just to be the type of the type tag. In other words,
the error span was previously this:
```
@type {IncorrectType}
```
But is now just this:
```
IncorrectType
```
Fixes the first error from #41974, but not the other two.
Co-authored-by: Ashya Manning <ashyamanning@pursuit.org>
Co-authored-by: Nilber Remon <nilberremon@gmail.com>
Co-authored-by: Ashya Manning <ashyamanning@pursuit.org>
Co-authored-by: Nilber Remon <nilberremon@gmail.com>
* fix as suggestion.
* Update moduleSpecifiers.ts
* compare symbol rather than string
* fix typo.
* fix
* fix lint.
* better name and more clear code
* fix comment.
Co-authored-by: Orta Therox <git@orta.io>
* Have signature identity checks look at the base constraint of type parameters, allow identical type parameter lists to merge in union signatures
* Update text in fourslash test
* Add whitespace to fix lint, remove duplicate impl
* Consolidate names
* Remove comparisons of type parameter defaults, add more test cases
* Explore at least 10 levels of constraints before checking for deeply nested types
* Simplify constraint depth limiter logic
* Add regression test
* Accept new baselines
* 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
* Detect comparisons between large unions or intersections
If their multiplied size is greater than 1E6 (chosen based on the repro
in #41517), then we'll expend a large amount of time and memory
comparing them, so record a trace event.
Related to #41517
* Make an exception for primitive union comparisons
* Address PR feedback
* Pick up baseline change from master
* Eliminate diagnostic and only trace
* Don't check reportErrors