Andrew Branch
bb6f36f7c8
Forward intersection state flag to conditional type target check ( #50620 )
2022-09-07 10:07:24 -07:00
Will Nayes
fd3a84c3f0
Report every instance of TS1208 ( #50101 )
...
* Report every instance of TS1208
* Test case for multiple cases of TS1208
* Add test case for isolatedModules with moduleDetection forced
2022-09-02 13:44:47 -07:00
Andrew Branch
856c7c5fdd
Allow {} to narrow in same special cases as unknown ( #50601 )
2022-09-02 09:47:27 -07:00
Anders Hejlsberg
854d448e5c
in operator shouldn't narrow {} originating in unknown (#50610 )
...
* 'in' operator shouldn't narrow {} originating in unknown
* Add regression test
2022-09-02 09:30:17 -07:00
Oleksandr T
bcf994996e
fix(50079): show deprecated on JSX attributes ( #50084 )
2022-09-01 16:59:29 -07:00
Andrew Branch
5df09a514c
Use bidirectional comparability in narrowing ( #50592 )
...
* Use bidirectional comparability (aka comparability) in narrowing
* Rename test, check other CFA branch, test without strictNullChecks
2022-09-01 14:26:48 -07:00
Anders Hejlsberg
6db2c882f3
{} & null and {} & undefined should always be never ( #50553 )
...
* {} & null and {} & undefined should be never in non-strictNullChecks mode
* Add tests
* Address code review feedback
* Accept new baselines
2022-09-01 12:37:13 -07:00
Mateusz Burzyński
238c341701
Defer distributing index over generic object types ( #50540 )
...
* Defer distributing index over generic object types
* Only check if the index type should be deferred for intersection types
* Add an additional test case
2022-09-01 07:28:13 -07:00
Oleksandr T
a9797d218d
fix(50340): typeof ... === "undefined" check on discriminated union of undefined and object type doesn't narrow correctly ( #50344 )
...
* fix(50340): narrow type by discriminant in typeof
* add additional test cases
2022-08-31 15:00:50 -07:00
Wesley Wigham
488d0eebd0
Retain name and propertyName in declaration emit copies of binding patterns if property name is a keyword ( #50537 )
...
* Retain name and propertyName in declaration emit copies of binding patterns if property name is a keyword
* Accept baselines
* Remove out of date file
2022-08-30 09:03:02 -07:00
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 9236e39374c0ec9a1e3f9894af4fb9eb34ba0021.
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 be387e3bbf8a5cce2bc4c31fd77b061ea6cf8e0b.
* 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