Commit graph

8142 commits

Author SHA1 Message Date
Daniel Rosenwasser a90389a22d
Switch deferredNodes from a Map to a Set. (#46751) 2021-11-23 17:46:33 -08:00
Oleksandr T 6143237376
fix(46366): handle enum string access as enumMemberName (#46431) 2021-11-18 15:50:32 -08:00
Oleksandr T a75f26e68b
fix(42238): emit this parameter in function declaration (#46511) 2021-11-17 15:43:27 -08:00
Oleksandr T 719ab0b477
fix(43359): emit default exports with named exports that have the same names with types (#44718) 2021-11-12 11:25:52 -08:00
Daniel Rosenwasser 416571ca90
Remove unnecessary annotations/casts/aliases (#46727)
* Remove unnecessary annotation.

* Remove more unnecessary stuff.

* Remove unnecessary assertion.
2021-11-09 12:17:54 -08:00
Oleksandr T 3ef3cdddb3
fix(45692): merge non-primitive in spread-union (#45729) 2021-11-05 15:41:06 -07:00
Oleksandr T ff75b8a180
fix(46615): remove useless assertion. change error suggestion for rest params (#46628) 2021-11-03 14:11:39 -07:00
Anders Hejlsberg 831b770b95
Control flow analysis for destructured discriminated unions (#46266)
* CFA for dependent variables destructured from discriminated union

* Accept new baselines

* Add tests

* Limit calls to isSymbolAssigned

* Fix wrong operator
2021-11-02 15:48:13 -07:00
Wesley Wigham de23842e45
Allow import assertions on esm imports under module: nodenext (#46630)
* Allow import assertions on esm imports under module: nodenext

* Changes to copy

Co-authored-by: Andrew Branch <andrew@wheream.io>
2021-11-02 15:34:37 -07:00
Anders Hejlsberg 33fe1b6ffc
Fix contextual typing for symbol-named properties (#46558)
* Properly handle symbol-named properties in contextual types

* Update index signature in PropertyDescriptorMap

* Add regression tests
2021-11-02 14:05:41 -07:00
Anders Hejlsberg 373accf28f
Improve recursion depth checks (#46599)
* Decrease recursion depth limit to 3 + smarter check for recursion

* Accept new baselines

* Always set last type id

* Keep indexed access recursion depth check

* Less expensive and corrected check for broadest equivalent keys
2021-11-02 14:05:17 -07:00
Anders Hejlsberg 56f81075f9
Properly check whether union type contains only primitive types (#46645)
* Properly check whether union type contains only primitive types

* Add regression test

* Remove 'export' modifier from test
2021-11-02 12:46:26 -07:00
Anders Hejlsberg 7cbcfeea99
Exclude identity relation from mapped type relation check (#46632)
* Exclude identity relation from mapped type relation check

* Add regression test
2021-11-02 06:54:35 -07:00
Daniel Rosenwasser 6d33d8797b
Check for type parameters on original type when getting type argument completions (#46614)
* Add failing test.

* Check for type parameters on the original type when asking for the type argument constraint.

* Update tests/cases/fourslash/stringLiteralTypeCompletionsInTypeArgForNonGeneric1.ts
2021-11-01 11:41:43 -07:00
Anders Hejlsberg b0ab2a54bb
Fix mapped type instantiation circularity (#46586)
* Don't obtain constraint if doing so would cause circularity

* Add regression test

* Address CR feedback
2021-10-29 14:01:27 -07:00
Gabriela Araujo Britto 9cdbb7248b
Improve errors on module: node12 and extensionless relative imports (#46486)
* add new error + suggestions

* push down assert defined

* remove comment

* fix esm module import detection, update baselines

* add and update new tests

* fix review comments

* remove renamed baseline references

* update node modules test baselines

* fix error message, add new tests

* update old tests with new error message
2021-10-29 10:25:03 -07:00
Gabriela Araujo Britto fd620c93f6
Add method signature completions (#46370)
* prototype creation for method override completion snippet

* WIP: start using codefix `addNewNodeForMemberSymbol` to create method decl node

* update type of addNewNodeForMemberSymbol

* add more tests and support more cases

* add more tests and fix some details

* wip: more fixes and tests

* expose check override modifier in checker

* fix test

* WIP: add snippet support

* WIP: snippet support on emitter, adding snippets in completions

* make add snippets work with overloads (not synced)

* fix snippet adding

* rebase

* WIP: try to add snippet escaping in emitter

* support escaping in snippets

* small fixes; fixed tests

* more tests and fixes

* fix new tests

* fix modifier inheritance for overloads

* merge conflict fixes; remove comments

* throw error if setOptions is called but not implemented

* fix newline handling

* fix weird stuff

* fix tests

* fix more tests

* Fix unbound host.getNewLine

* fix isParameterDeclaration changes

* rename diagnostic to status and remove snippets from public api

* rename emitter functions + fix indentation

* check completion kind before calling isclasslikemembercompletion

* fix missing type parameters

* Revert "fix missing type parameters"

This reverts commit 7bdeaa86da.

* add isAmbient flag to addNewNodeForMemberSymbol

* add test for abstract overloads

* refactor snippet escaping support

* add user preference flag for enabling class member snippets

* update API baseline

* update tabstop order

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2021-10-28 16:05:36 -07:00
Daniel Rosenwasser f494742ce9
Check for array types when instantiating mapped type constraints with any (#46218)
* Added/updated tests.

* Accepted baselines.

* Update test.

* Update instantiateMappedType to work specially when 'any' replaced an array.

* Accepted baselines.

* Ensure check works when constraint is a union of arrayish types, just like in `Promise.all`.

* Accepted baselines.

* Update test for indirect instantiation of a mapped type.

* Accepted baselines.

* Update test comment.

* Accepted baselines.

* Added tuple test case.

* Accepted baselines.

* Don't add special behavior for tuples.

* Accepted baselines.

* Revert "Don't add special behavior for tuples."

This reverts commit f01ae16e65.

* Accepted baselines.
2021-10-27 15:03:01 -07:00
Wesley Wigham abfd537503
Support resolveJsonModule in new module modes (#46434)
* Support resolveJsonModule in new module modes

* Formatting feedback
2021-10-27 12:30:06 -07:00
Zzzen 8a68c8616d
allow typeof this after for-loops (#46181) 2021-10-27 10:26:05 -07:00
Anders Hejlsberg f424dfc18a
Slightly less conservative check in isConstraintPosition (#46526)
* Slight adjustment to check in isConstraintPosition

* Add regression test
2021-10-26 11:54:46 -07:00
Anders Hejlsberg 44c63a757e
Always cache relations involving intersection types (#46523)
* Always cache relations involving intersection types

* Accept new baselines

* Add regression test
2021-10-26 09:36:19 -07:00
Anders Hejlsberg 658764e499
Bypass caching in removeStringLiteralsMatchedByTemplateLiterals (#46525)
* Bypass caching in removeStringLiteralsMatchedByTemplateLiterals

* Add regression test
2021-10-26 09:34:15 -07:00
Andrew Branch 3519af0bab
Fix crash pulling on global types before they're initialized (#46471)
* Add failing test

* Dumb fix

* Compute error message info more lazily

* One more laziness
2021-10-25 10:53:41 -07:00
Andrew Branch 907fc72db4
Fix auto import crash on weird JS aliasing (#46490)
* Fix auto import crash on weird JS aliasing

* Comment up the weird test

* Fix setting members on union/intersection type, happens later
2021-10-22 16:09:32 -07:00
Anders Hejlsberg 449aaa118f
Defer computation of isDistributionDependent to avoid circularities (#46474)
* Defer computation of isDistributionDependent to avoid circularities

* Accept new API baselines
2021-10-22 09:13:54 -07:00
Anders Hejlsberg f2f35ae78b
Simplify relationship check for conditional type on target side (#46429)
* Simplify relationship check for conditional type on target side

* Accept new baselines

* Better support for non-distribution-dependent types

* Accept new API baselines

* Accept new baselines
2021-10-21 17:35:23 -07:00
Anders Hejlsberg 56b6279818
Improve logic for choosing between co- and contra-variant inferences (#46392)
* Improve logic for choosing between co- and contra-variant inferences

* Add tests
2021-10-19 09:58:10 -07:00
Nathan Shively-Sanders 8d715ff53e
Error on mapped type w/properties (#46346)
* Error on mapped types with properties

1. Error on properties of type literals with computed properties whose name is a
binary expression with `in`, because that's a good sign of a mapped
type.
2. Parse following properties on mapped types, and error on them.
3. Stop checking computed property names in (1) to avoid producing
errors based on misinterpreting mapped type syntax as an expression.

* add comment in types.ts

* Update API again

* Check interfaces and classes too

* Add missed check in updateMappedTypeNode
2021-10-18 09:00:00 -07:00
Oleksandr T 7582b1bbae
fix(45799): skip checking arguments used as a key in object literals (#45814) 2021-10-15 10:34:57 -07:00
Anders Hejlsberg 8718df3dc1
Fix stack overflow in JSX discriminated union logic (#46354)
* Use getContextFreeTypeOfExpression to avoid circularities

* Add regression test
2021-10-14 10:11:44 -07:00
Wesley Wigham 1c5d4e1740
Pass symbol under inspection into checkIndexConstraints (#46350) 2021-10-13 17:04:33 -07:00
Anders Hejlsberg 0d2aeb7c65
Improve checks for infinitely expanding recursive conditional types (#46326)
* Improve checks for infinitely expanding recursive conditional types

* Accept new baselines

* Add regression tests

* Remove 'export' modifier

* Accept new baselines
2021-10-13 07:08:01 -07:00
Wesley Wigham 713afe2227
Set import mode on synthetic imports (#46327) 2021-10-12 16:23:37 -07:00
Yuya Tanaka 9e2fc16c32
Improve perf of unions with many primitives (#45220) 2021-10-12 16:07:21 -07:00
Nathan Shively-Sanders 8c270757b2
In plain JS files, only suggestion did-you-mean errors (#46151)
They will have code fixes, and are tuned for high precision. Others are
not.
2021-10-07 08:41:06 -07:00
chenjigeng d60747f043
Feat/quick fix for types (#42126)
* feat: add quick fix for types

* feat: add test case for quick fix of types

* feat: add did-you-mean error when Cannot_find_name_0 and Cannot_find_namespace_0

* feat: add Cannot_find_namespace_0_Did_you_mean_1 error and only suggest when resolve type

* feat: update baselines

* feat: update baselines

* feat: update baselines

* chore: fix style problem

* Always suggest spelling corrections

* suggest primitives instead of their wrappers

* Add primitives to suggestions

Instead of altering wrappers to look like primitives.

* add semicolons

* revert unneeded change

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-10-05 08:14:16 -07:00
Wesley Wigham ccc19092ff
Modify synthetic default generation code for dual-mode module resolution (#46156) 2021-10-01 09:18:44 -07:00
Wesley Wigham 612c92d603
Track source and target relationship stack depth seperately, only increase on change in value (#41821)
* Track source and target relationship stack depth seperately, only increase on change in value

* Add baselines for test from #43485

* Bail on unwrapping conditional constraints on the source side when the source conditional is already known to be spooling out of control

* More usage of isDeeplyNestedType to block _specifically_ conditional recursion on only one side

* Negative cases of getNarrowedType that match the exact type should be filtered out, even when generic

* Add test and fix for #44404

* Swap to manually specifying left and right recursion

* Rename Left -> Source, Right -> Target

Co-authored-by: Andrew Branch <andrew@wheream.io>
2021-09-30 16:58:40 -07:00
Oleksandr T d613748932
fix(45919): allow using JSDoc types for arrow function with type predicate (#45952) 2021-09-30 10:50:25 -07:00
Oleksandr T e0f436c628
feat(36080): forbid to use JSDoc visibility modifiers in private fields (#46056) 2021-09-30 09:48:56 -07:00
Kagami Sascha Rosylight 2161e1852f
Add module: es2022 (#44656)
Closes #44653
2021-09-29 17:44:57 -07:00
Anders Hejlsberg 5ec836db82
Fix issues + Support template literal types as discriminants (#46137)
* Fix issues + Support template literal types in discriminants

* Add tests

* Address CR feedback
2021-09-29 17:38:43 -07:00
Oleksandr T e96c10fe0c
fix(26635): allow casts only when JSDoc type directly attached to an expression (#45960) 2021-09-29 12:16:27 -07:00
Hiroshi Ogawa 061f02cd64
fix(44021): reference jsx pragma when JsxFragment is used (#45894) 2021-09-29 11:31:59 -07:00
Wesley Wigham 8d5c197f99
keyof should always include remapped keys (#45923)
* Loosen check in getIndexTypeForMappedType to directly map property names when any indexy type is present

* Handle homomorphic mappings better in keyof, add specific relationship rule for relating generic keyof MappedType to handle remapped keys

* Remove trailing whitespace
2021-09-27 19:10:02 -07:00
Andrew Branch e160bc8c0d
Type-only import specifiers (#45998)
* Parse type-only import specifiers

* Add type-only export specifiers

* Update transform and emit

* Update checking

* Fix elision when combined with importsNotUsedAsValues=preserve

* Accept baselines

* Add test

* WIP auto imports updates

* First auto-imports test working

* More auto-import tests

* Fix auto imports of type-only exports

* Add test for promoting type-only import

* Sort import/export specifiers by type-onlyness

* Update completions for `import { type |`

* Update other completions tests

* Respect organize imports sorting when promoting type-only to regular while adding a specifier

* Fix comment mistakes

* Update src/services/codefixes/importFixes.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Rearrange some order of assignments in parser

* Split huge if statement

* Remove redundant check

* Update new transformer

* Fix import statement completions

* Fix type keyword completions good grief

* Fix last tests

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-09-27 12:38:30 -07:00
Anders Hejlsberg 26aef89a72
Make never inferences with template literal types only in special cases (#46075)
* Make 'never' inferences with template literal types only in special cases

* Accept new baselines

* Add regression test

* Fix comment
2021-09-27 06:47:47 -07:00
Anders Hejlsberg 2f0c6070cb
Properly handle missingType in intersections (#46052)
* Properly handle missingType in intersections

* Add regression tests

* Accept new baselines

* Fix tests
2021-09-26 14:13:42 -07:00
Wesley Wigham 586b0d5011
moduleResolution: node12 support (#45884)
* Initial support for module: node12

* Add allowJs and declaration emit enabled tests

* Fix typos

* cts, mts, cjs, mjs, etc extension support

* Fix watch of files whose intepretation changes due to a package.json update

* Minor PR feedback

* Adjust error message

* Initial import/export/self-name support

* Accept new error codes

* TypesVersions support in export/import map conditions

* Fix import suggestion and autoimport default extensions under new resolution modes

* Add tests for import maps non-relative name lookup feature

* Fix isDeclarationFileName for .d.mts and .d.cts

* Preserve new extensions when generating module specifiers

* Fix spurious implict any suggestion caused by file ordering bug and optimize import name format detection by relying on parents being set

* Fix a bunch of incremental bugs that dont repro under fourslash for some reason

* Accept updated baseline

* Always include extensions on completions for cjs/mjs style imports

* String completion relative import suggestions respect the mode of the import when choosing if they provide extensions

* Style feedback

* Change diagnostic case
2021-09-24 14:25:59 -07:00