Anders Hejlsberg
6d170b490d
Handle intersections in isGenericTypeWithoutNullableConstraint ( #50497 )
...
* Handle intersections in isGenericTypeWithoutNullableConstraint
* Add regression test
2022-08-29 09:24:13 -07:00
Joost Koehoorn
71b2ba6111
Reuse computed type of condition expressions ( #49881 )
2022-08-27 01:40:13 -07:00
Oleksandr T
4579245f36
fix(50427): allow convert function expressions ( #50430 )
2022-08-26 15:43:19 -07:00
Oleksandr T
bb3a7aec11
fix(50415): Language server debug failure - Did not expect GetAccessor to have an Identifier in its trivia ( #50470 )
...
* fix(50415): clone props for get/set accessors
* add additional tests
* create helpers to create name, body, modifiers, typeName
* cleanup
2022-08-26 14:33:23 -07:00
Oleksandr T
164dddc48e
feat(7481): Operator to ensure an expression is contextually typed by, and satisfies, some type ( #46827 )
...
* feat(7481): add explicit type compatibility check with 'satisfies' expression
* Add failing test for lack of intersectioned contextual type
* Implement the behavior
* Add test corresponding to the 'if'
* Add test based on defined scenarios
* remove isExpression in favor of using type casting
* move tests from compiler to conformance folder
* update baseline
* add missing contextFlags argument
* use asserted type
* accept baseline
Co-authored-by: Ryan Cavanaugh <ryanca@microsoft.com >
2022-08-26 10:05:52 -07:00
Andrew Branch
38076df346
Fix auto import crash due to difference in paths handling ( #50419 )
2022-08-25 13:02:48 -07:00
Oleksandr T
12eb519b3f
fix(50435): Duplicate seeming Code Actions for convert const to let ( #50442 )
...
* fix(50435): omit fix all in constToLet QF
* add FixAll action
2022-08-25 13:01:46 -07:00
Danay
a08b045d2b
Jsdoc property description ( #50269 )
...
* jsdocPropertyDescription
* jsdocPropertyDescription
* jsdocPropertyDescription
* Fixes #47933
* added additional test
* added additional example
* fixed bug
* changed function to only grab the literal type
* added additional condition for literals and symbols
* added additional test cases
* Update src/services/symbolDisplay.ts
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com >
* addressed PR review
* addressed new PR review
Co-authored-by: Danay Fernandez Alfonso <t-danayf@microsoft.com >
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com >
2022-08-25 11:57:32 -07:00
Oleksandr T
8d7ad8c3ae
fix(50375): Errors for missing enum-named properties should attempt to preserve names ( #50382 )
...
* fix(50375): preserve enum-named properties
* add AllowComputedPropertyEnums option
* use bit shifting
* rename AllowComputedPropertyEnum -> WriteComputedProps
* mark WriteComputedProps as internal
* mark symbolToNode as internal
2022-08-24 11:54:44 -07:00
Daniel Rosenwasser
fb717df6bf
Discard union types before considering weak type checks on unit-like types ( #50423 )
...
* Only check isUnitType when dealing with non-unions.
* Add test case.
* Accepted baselines.
2022-08-24 11:39:00 -07:00
Oleksandr T
44ce3cff70
fix(50224): Intellisense for strings within a type's Union doesn't work properly for JSX ( #50231 )
...
* fix(50224): show string literal completions in JsxAttributeInitializer
* add feedback changes
2022-08-23 14:59:10 -07:00
Oleksandr T
5969ae9ef7
fix(50075): do not strip undefined from the function class properties ( #50169 )
2022-08-19 09:34:42 -07:00
Wesley Wigham
05d7d6bb12
Unify default import resolution across specifier target codepaths ( #49814 )
...
* Unify default import resolution across specifier target codepaths
* Use differing type aliases, per request
2022-08-19 02:25:41 -07:00
Daniel Rosenwasser
7bafbeae90
Add fourslash function for validating syntactic classification ( #50362 )
2022-08-18 11:28:08 -07:00
DetachHead
3b80ddca21
fix first match in RegExpMatchArray being possibly undefined when noUncheckedIndexedAccess is enabled ( #49682 )
...
* fix first match in `RegExpMatchArray` being possibly undefined when `noUncheckedIndexedAccess` is enabled
* fix tests
* add test
Co-authored-by: DetachHead <detachhead@users.noreply.github.com >
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com >
2022-08-16 10:12:12 -07:00
Andrew Branch
330e33cdda
Ignore related info in diagnostic deduplication ( #50309 )
...
* Ignore related info in diagnostic deduplication
* Add another test
2022-08-16 09:28:59 -07:00
Babak K. Shandiz
f24f74eb89
🔨 Fix missing "Implement interface" code fix for mapped types with implicit keyof T in their definition ( #49999 )
...
* ⚗️ Add test to verify code fix works when implementing a mapped type with indirect keyof
Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com >
* 🔨 Add property as implementation for symbols that has no declaration
Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com >
diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts
index 94b64e57..a4c11fd5 100644
--- a/src/services/codefixes/helpers.ts
+++ b/src/services/codefixes/helpers.ts
@@ -60,21 +60,19 @@ namespace ts.codefix {
isAmbient = false,
): void {
const declarations = symbol.getDeclarations();
- if (!(declarations && declarations.length)) {
- return undefined;
- }
+ const declaration = declarations ? declarations[0] : undefined;
const checker = context.program.getTypeChecker();
const scriptTarget = getEmitScriptTarget(context.program.getCompilerOptions());
- const declaration = declarations[0];
+ const kind = declaration?.kind ?? SyntaxKind.PropertySignature;
const name = getSynthesizedDeepClone(getNameOfDeclaration(declaration), /*includeTrivia*/ false) as PropertyName;
- const visibilityModifier = createVisibilityModifier(getEffectiveModifierFlags(declaration));
+ const visibilityModifier = createVisibilityModifier(declaration ? getEffectiveModifierFlags(declaration) : ModifierFlags.None);
const modifiers = visibilityModifier ? factory.createNodeArray([visibilityModifier]) : undefined;
const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
const optional = !!(symbol.flags & SymbolFlags.Optional);
const ambient = !!(enclosingDeclaration.flags & NodeFlags.Ambient) || isAmbient;
const quotePreference = getQuotePreference(sourceFile, preferences);
- switch (declaration.kind) {
+ switch (kind) {
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyDeclaration:
const flags = quotePreference === QuotePreference.Single ? NodeBuilderFlags.UseSingleQuotesForStringLiteralType : undefined;
@@ -88,13 +86,16 @@ namespace ts.codefix {
}
addClassElement(factory.createPropertyDeclaration(
modifiers,
- name,
+ declaration ? name : symbol.getName(),
optional && (preserveOptional & PreserveOptionalFlags.Property) ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
typeNode,
/*initializer*/ undefined));
break;
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor: {
+ if (!declarations) {
+ break;
+ }
let typeNode = checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context));
const allAccessors = getAllAccessorDeclarations(declarations, declaration as AccessorDeclaration);
const orderedAccessors = allAccessors.secondAccessor
@@ -138,6 +139,10 @@ namespace ts.codefix {
// If there is more than one overload but no implementation signature
// (eg: an abstract method or interface declaration), there is a 1-1
// correspondence of declarations and signatures.
+ if (!declarations) {
+ break;
+ }
+
const signatures = checker.getSignaturesOfType(type, SignatureKind.Call);
if (!some(signatures)) {
break;
* 🔨 Improve code readability
Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com >
diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts
index 2f5c8703ab..aea0206a8a 100644
--- a/src/services/codefixes/helpers.ts
+++ b/src/services/codefixes/helpers.ts
@@ -60,7 +60,7 @@ namespace ts.codefix {
isAmbient = false,
): void {
const declarations = symbol.getDeclarations();
- const declaration = declarations ? declarations[0] : undefined;
+ const declaration = declarations?.[0];
const checker = context.program.getTypeChecker();
const scriptTarget = getEmitScriptTarget(context.program.getCompilerOptions());
const kind = declaration?.kind ?? SyntaxKind.PropertySignature;
@@ -93,9 +93,7 @@ namespace ts.codefix {
break;
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor: {
- if (!declarations) {
- break;
- }
+ Debug.assertIsDefined(declarations);
let typeNode = checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context));
const allAccessors = getAllAccessorDeclarations(declarations, declaration as AccessorDeclaration);
const orderedAccessors = allAccessors.secondAccessor
@@ -139,10 +137,7 @@ namespace ts.codefix {
// If there is more than one overload but no implementation signature
// (eg: an abstract method or interface declaration), there is a 1-1
// correspondence of declarations and signatures.
- if (!declarations) {
- break;
- }
-
+ Debug.assertIsDefined(declarations);
const signatures = type.isUnion() ? flatMap(type.types, t => t.getCallSignatures()) : type.getCallSignatures();
if (!some(signatures)) {
break;
* 📜 Add comment regarding mapped type children's missing declaration
Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com >
Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com >
Co-authored-by: Andrew Branch <andrew@wheream.io >
2022-08-16 09:27:29 -07:00
Andrew Branch
4e33e0eb6c
Make literal types not comparable to weak object types without property overlap ( #49865 )
2022-08-15 17:10:11 -07:00
Andrew Branch
64ee1e88e0
Strip literal freshness of contextually typed literals ( #49884 )
...
* Strip literal freshness of contextually typed literals
* Add more tests
2022-08-15 17:04:09 -07:00
Wesley Wigham
e989d840f1
Forward intersectionState flag when comparing indexed access constraints ( #50261 )
2022-08-15 16:10:32 -07:00
Oleksandr T
61d8a8d7f3
fix(49629): fix crash in find-all-refs when using module.exports/export= with arrays/primitives ( #50291 )
2022-08-15 15:14:26 -07:00
Andrew Branch
bc52ff6f4b
Make React import fix not block component import fix ( #50307 )
...
* Stop React import fix from blocking component import fixes
* Add additional promote-type-only test
2022-08-15 13:13:41 -07:00
Ryan Cavanaugh
adf26ffa4b
Revert "Fixed an issue with contextual type for intersection properties ( #48668 )" ( #50279 )
...
This reverts commit 9236e39374 .
2022-08-12 10:24:50 -07:00
Jake Bailey
5fbf3b04dc
Don't treat object properties as potential JS contructors without JSDoc class tag ( #49735 )
2022-08-10 11:19:19 -07:00
Jack Works
382f0c3af3
fix: crashes when JSX.IntrinsicClassAttributes is an alias type close GH-50254 ( #50257 )
2022-08-10 10:41:12 -07:00
Jack Bates
35c6fbfee0
JSDoc @type tag optional parameters ( #48132 )
...
* JSDoc @type tag optional parameters
* Don't repeat isInJSFile() condition
* Exclude variable initializers
* Add tests for class methods
* Don't contextually type JS function declarations
* Update Baselines and/or Applied Lint Fixes
* Reword comment
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com >
2022-08-09 17:03:30 -07:00
Zzzen
b94b299a11
fix CFA for BindingElement. #49759 ( #49836 )
...
* fix CFA for BindingElement. #49759
* fix Parameter
* fix controlFlowBindingPatternOrder
* fix bindParameterFlow
* add tests
* refactor
* refactor
* refactor
2022-08-09 16:37:39 -07:00
Nathan Shively-Sanders
dd98c17b10
Merge multiple symbols even when re-exported ( #49987 )
...
* Merge multiple symbols even when re-exported
As far as I remember, the target of `mergeSymbol` needs to be a merged
symbol, not a symbol with a mergeId that points to mergedSymbol.
However, mergeSymbolTable didn't check for this.
I can't remember if symbol tables may contain
symbols-with-mergeId. If they can, then mergeSymbolTable needs to call
getMergedSymbol on the individual targets of the merge. That's what I
did in this PR.
* Call getMergeSymbol eagerly
On the source, not target, of mergeSymbolTable's contents
2022-08-09 16:36:53 -07:00
magic-akari
abc2a350e6
Fix System module export import = ( #49788 )
...
* Add more SystemJS test case
* Fix System module `export import =`
* Update test case
2022-08-09 16:31:02 -07:00
Oleksandr T
f70cb769ef
feat(49928): Provide quick fix for a missing callback function ( #49930 )
...
* feat(49928): provide quick fix for a missing callback function
* remove addFunctionDeclarationFromSignature. fix formatting
* add tests
2022-08-09 15:28:03 -07:00
Oleksandr T
19e2a310c0
feat(49834): Suggestion: filter enum member ids from their own jsdocs ( #49843 )
...
* feat(49834): omit self-referenced enum declaration in JsDoc
* change code style
2022-08-09 15:02:45 -07:00
Mateusz Burzyński
0e17dc7769
Fixed a false positive related to binding patterns and spread expressions ( #49684 )
...
* Fixed a false positive related to binding patterns and spread expressions
* Improve ancestor lookup when checking if an expression is spread into an object
* Fixed ancestor lookup for more node types
* Remove equality check for contextual types
* Reformat code
* Use `isWithinSpreadAssignment` flag + `objectsWithinSpread` cache instead of ancestor traversal
* Revert "Use `isWithinSpreadAssignment` flag + `objectsWithinSpread` cache instead of ancestor traversal"
This reverts commit be387e3bbf .
* Expand on the existing comment
2022-08-08 17:01:50 -07:00
Gabriela Araujo Britto
bdb8514b82
Fix contextual typing on yield and return expressions in generator function ( #49736 )
...
* add tests and initial fix
* fix contextual return type in generator funcs
* fix return statement contextual typing
* filter using getiterationtypeofgeneratorfunctionreturntype
* update baselines
2022-08-05 11:24:43 -07:00
Oleksandr T
a44354af7c
fix(50188): omit QF on function arguments ( #50189 )
2022-08-04 17:52:09 -07:00
Andrew Branch
7afd14f263
Update error messages for CJS imports resolving to ES modules ( #50088 )
...
* Update error messages for CJS imports resolving to ES modules
* Update error message
* Use package scope from source file
* Update baselines
* Issue error for JSX/TSX files
* Switch from related info to message chain
2022-08-04 16:58:13 -07:00
Ron Buckton
6bbe6d67d1
Fix return value and error reporting for getIterationTypesOfMethod ( #50146 )
2022-08-03 19:07:29 -04:00
Ron Buckton
d6d26430c7
Add rule to auto-paren optional chain in normal prop or element access ( #50156 )
2022-08-03 17:17:26 -04:00
Andrew Branch
c82c9a9744
Fix bugs in module specifier generation with paths/typesVersions ( #49792 )
...
* Write a test and a huge comment
* Finish fixing everything
* Clean up comment
* Remove obsolete comment
* Fix comment trailing off
* Optimize to hit the file system much less
2022-08-03 13:58:15 -07:00
Oleksandr T
59c91f6ce9
fix(50077): skip convertOverloadListToSingleSignature refactoring if position is in function body ( #50093 )
2022-08-03 13:56:42 -07:00
Jack Bates
040c1216ff
Better typings for Promise.resolve(), like #31117 ( #33074 )
...
* Better typings for Promise.resolve(), like #31117
* Add tests
* Update to Awaited<T>
* Fix issue with Awaited affecting jQuery, additional tests
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com >
2022-08-02 13:39:50 -04:00
Oleksandr T
c0072aad80
fix(49935): omit parentheses in the operand of the unary expression ( #50111 )
2022-08-01 17:22:45 -04:00
Ron Buckton
55f2c0cb49
No synthetic Awaited for unconstrained type when not a type variable ( #50100 )
2022-08-01 17:19:15 -04:00
Nathan Shively-Sanders
427d43691a
Improve import type support for commonjs exports ( #49745 )
...
* Improve import type support for commonjs exports
This PR makes getTypeFromImportTypeNode a little more like
getExternalModuleMember: for JS files, it now uses both
`getTypeOfSymbol` and `getExportsOfSymbol`, and uses whichever one
returns a symbol. This allows using arbitrary properties of a CJS export=
as types in JSDoc; previously a special case in the binder enabled only
CJS export= where all properties were shorthand assignments.
Fixes #49195
* Add js types/value test case
* Improve binding of CJS property assignments
1. Bind property assignments same as shorthand property assignments in
module.exports object literal assignments.
2. Bind all such assignments, even if the object literal contains
non-property assignments. This is different from before, and it requires
slightly smarter code to prefer aliases when checking CJS imports.
* Remove new binder code
Just include the original fix
* revert missed type in binder
2022-08-01 10:57:38 -07:00
Oleksandr T
ae7d2325e9
fix(49869): throw an error on optional binding pattern parameter in JavaScript ( #50094 )
2022-07-29 16:05:34 -07:00
Ron Buckton
88a1e3a1dd
Transform decorators that reference private names into a 'static {}' block ( #50074 )
2022-07-29 15:29:48 -04:00
Mateusz Burzyński
5374fd924e
Add an additional test for favoring the asserted type in type predicate narrowing ( #50065 )
...
* Add an additional test for favoring the asserted type in type predicate narrowing
* Add requested test cases
2022-07-29 12:12:33 -07:00
Zzzen
1490037f17
fix dts generation of jsdoc ( #49904 )
2022-07-28 17:44:23 -07:00
Oleksandr T
949fffb1e0
feat(47983): Negative tuple index access should not be allowed ( #49901 )
...
* feat(47983): disallow negative integers for indexing tuple
* change error message
* add additional tests
2022-07-28 14:22:13 -07:00
Andrew Branch
b7355e30af
Fix trailing formatting edit when range ends mid-token ( #50082 )
2022-07-28 12:11:22 -07:00
Oleksandr T
94bb950008
feat(49358): use filename based on exported name ( #49875 )
2022-07-27 15:41:31 -07:00