Commit Graph
100 Commits
Author SHA1 Message Date
Anders Hejlsberg 58650d97c5 Fix narrowing of destructured tuples with different arities (#55744) 2023-09-14 13:06:48 -07:00
Anders Hejlsberg 4f899a1691 Track recursive homomorphic mapped types by the symbol of their target (#55638) 2023-09-11 14:03:00 -07:00
Anders HejlsbergandMateusz Burzyński 753c463821 Only infer readonly tuples for const type parameters when constraints permit (#55229)
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2023-08-26 08:20:55 -07:00
Anders Hejlsberg fcaa900012 Fix check in getDiscriminantPropertyAccess (#55464) 2023-08-23 11:43:41 -07:00
6d07d5fa40 Improve inference between types with multiple signatures (#54448)
Co-authored-by: Ryan Cavanaugh <RyanCavanaugh@users.noreply.github.com>
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2023-08-23 11:14:25 -07:00
Anders Hejlsberg c69f4476af Handle composite signatures in isResolvingReturnTypeOfSignature (#55165) 2023-07-26 15:22:58 -07:00
Anders Hejlsberg cbf3c63ef3 Revert overly permissive indexed access constraints (#54845) 2023-07-26 07:02:40 -07:00
Anders Hejlsberg 84d8429fb6 Add depth limiter to isConstTypeVariable function (#54624) 2023-06-16 12:48:44 -07:00
Anders Hejlsberg 89cbea8e16 No this type arguments in base constraints (#54536) 2023-06-12 19:07:44 -07:00
Anders Hejlsberg f5ab714d1f Suppress error caused by intermediate types in getTypeOfExpression (#54380) 2023-05-26 09:30:06 -07:00
Anders Hejlsberg 6f7704e0e2 Properly handle typeof this.xxx in isTypeParameterPossiblyReferenced (#54208) 2023-05-20 09:37:35 -04:00
Anders Hejlsberg 1ea21e1ef1 Fix isGenericReducibleType to allow HKT technique to function again (#54112) 2023-05-20 09:36:38 -04:00
Anders Hejlsberg 215fe6ef75 Fix creation of composite union type predicates (#54169) 2023-05-19 16:15:46 -04:00
Anders Hejlsberg 44f4e276b7 Constraints for generic tuple types (#53672) 2023-05-02 10:35:49 -07:00
Anders Hejlsberg 94564cf073 Type with diverging read/write normalizations still identical to itself (#54033) 2023-05-02 06:40:41 -07:00
Anders Hejlsberg ae6393e5eb Add fallback when both co- and contra-variant inference candidates exist (#54072) 2023-05-02 06:39:57 -07:00
Anders Hejlsberg e782cef221 Properly handle partial union type properties in isTypePresencePossible (#53794) 2023-04-16 17:24:10 -07:00
Anders Hejlsberg f8b3ea7972 Propagate errorType in getConditionalType (#53801) 2023-04-16 16:15:55 -07:00
Anders Hejlsberg e49db97f97 Exclude parameters of non-inferrable signatures from inference (#53756) 2023-04-14 12:44:37 -07:00
Anders Hejlsberg b798e6bfa5 Optimize union type creation (#53771) 2023-04-14 09:34:12 -07:00
Anders HejlsbergandMaria Solano bec204c844 Revise discriminateTypeByDiscriminableItems function (#53709)
Co-authored-by: Maria Solano <mariasolano@microsoft.com>
2023-04-12 07:25:58 -07:00
Anders Hejlsberg 3f675b60bf More complete check in isConstTypeVariable (#53341) 2023-04-01 14:45:31 -07:00
Anders Hejlsberg b40385b595 Explicit undefined return type checked similar to explicit void return type (#53607) 2023-04-01 14:44:52 -07:00
Anders Hejlsberg 511921e1e2 Improve detection of cases where subtype reduction is unnecessary (#53435) 2023-03-23 07:09:12 -07:00
Anders Hejlsberg 37bafa539c Exclude comparable relation from literal type relation optimization (#53419) 2023-03-23 07:04:16 -07:00
Anders HejlsbergandDaniel Rosenwasser 25550bd3d6 Exclude special index signature rule from strict subtype relation (#53388)
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2023-03-23 07:03:09 -07:00
Anders Hejlsberg 3d2c3442db Fix recursive type inference (#53396) 2023-03-21 12:53:16 -07:00
Anders Hejlsberg bace6897e2 Fix subtype reduction involving type variables with union constraints (#53351) 2023-03-21 12:52:05 -07:00
Anders Hejlsberg b70784ef8f Improve detection of type variables in instantiated object types (#53246) 2023-03-19 08:13:57 -07:00
Anders Hejlsberg 9b7f291a33 Improve contextual typing of ending tuple elements (#53036) 2023-03-19 08:13:03 -07:00
Anders Hejlsberg a70c4095db Fast path for negative case when relating to unions of primtives (#53192) 2023-03-17 08:10:48 -07:00
Anders Hejlsberg 9769421a63 Defer resolution of indexed access types with reducible object types (#53098) 2023-03-14 14:15:32 -07:00
Anders Hejlsberg 6823559fa9 Check for strict subtypes and then regular subtypes in getNarrowedType (#52984) 2023-03-03 15:56:17 -08:00
Anders Hejlsberg 74814345ce Omit intersection property check when source includes target (#53012) 2023-02-28 06:57:10 -08:00
Anders Hejlsberg 5c92af1dcc Fix contextual typing for post-spread tuple elements (#52769) 2023-02-18 07:35:24 -10:00
Anders Hejlsberg 7d00bb078d Widening and non-widening computed enum types (#52542) 2023-02-14 16:25:46 -08:00
Anders Hejlsberg 84b8483206 Improvements to strictSubtypeRelation and getNarrowedType (#52282) 2023-02-14 12:12:42 -08:00
Anders Hejlsberg 72fb827045 Check conditional types in depth in isTypeParameterAtTopLevel (#52648) 2023-02-14 07:33:22 -08:00
Anders Hejlsberg c838b0cb7e Consult cached contextual types only when no contextFlags (#52611) 2023-02-10 11:17:59 -08:00
Anders Hejlsberg bd905d4936 Fix crash in union subtype reduction involving template literal and string mapping types (#52699) 2023-02-09 15:04:57 -08:00
Anders Hejlsberg 57ebd99ff2 Exclude typeof this from check in isConstantReference (#52680) 2023-02-09 07:06:09 -08:00
Anders Hejlsberg 720ec45be5 Improve handling of corner cases in narrowTypeByInstanceof (#52592) 2023-02-06 11:32:33 -08:00
Anders Hejlsberg 30993855fd Consistently propagate intersectionState in relations (#52392) 2023-02-02 07:19:00 -08:00
Anders Hejlsberg d656487fca Permit instantiation expressions in typeof import(...) (#52532) 2023-02-01 09:09:55 -08:00
Anders Hejlsberg 41e4139357 Only used cached undefined contextual type for requests with no flags (#52224) 2023-01-13 10:10:56 -08:00
Anders Hejlsberg d6de73b20a Instantiate rest type as needed in getNarrowedTypeOfSymbol (#52215) 2023-01-13 07:23:39 -08:00
Anders Hejlsberg 36e9570933 Propagate constness of type parameters in variadic tuples (#52129) 2023-01-13 07:23:04 -08:00
Anders Hejlsberg 59e4e38d08 Don't widen when type parameter occurs at top level in type predicate (#52031) 2023-01-12 13:18:36 -08:00
Anders Hejlsberg 400e2c2bd8 Defer conditional types with multi-element tuple types in extends clause (#52091) 2023-01-06 09:18:12 -08:00
Anders Hejlsberg fc8538608b Improve logic that chooses co- vs. contra-variant inferences (#52123) 2023-01-06 07:56:51 -08:00
Anders Hejlsberg acf854b636 Keep track of multiple current inference contexts (#51978)
* Keep track of multiple current inference contexts

* Add regression test
2022-12-22 07:52:49 -10:00
Anders Hejlsberg 02d5b23aae Allow const modifiers on class expression type parameters (#51935)
* Allow `const` modifiers on class expression type parameters

* Add regression test
2022-12-17 10:32:27 -08:00
Anders Hejlsberg fede84e85b const modifier on type parameters (#51865)
* `const` modifier on type parameters + revised contextual type logic

* Accept new baselines

* Fix modifier checking

* Add tests

* Cache isConstTypeVariable check

* Revert "Cache isConstTypeVariable check"

This reverts commit f8fd1fd29f.

* Fewer isConstTypeParameterContext checks

* Pay attention to cached `undefined` contextual type

* Allow `const` modifier in more places + properly print back

* Also permit `const` in method signature type parameters

* Fix parsing of `const` modifier in array expression type parameters

* Accept new baselines

* Remove unused properties from NodeLinks

* Rename `permitInvalidConstAsModifier` to `permitConstAsModifier`
2022-12-16 13:47:10 -08:00
Anders Hejlsberg ba793e6069 Fix excess property checking for intersections with index signatures (#51894)
* Fix excess property checking for intersections with index signatures

* Add regression tests

* Limit check to only fresh object literals on the source side
2022-12-16 06:59:23 -08:00
Anders Hejlsberg b9d0e17298 Ignore switch statement bypass control flows that produce never (#51703)
* Ignore switch statement bypass control flows that produce 'never'

* Add regression test
2022-12-07 16:19:09 -08:00
Anders Hejlsberg d43112a75b Use missingType in --noUncheckedIndexedAccess mode (#51653)
* Use missingType in noUncheckedIndexedAccess mode

* Accept new baselines

* Add tests

* Optimizing searching for undefinedType and missingType
2022-12-07 13:38:33 -08:00
Anders Hejlsberg 91f89b94e4 Visit child nodes in checkExpressionWithTypeArguments (#51804)
* Visit child nodes in checkExpressionWithTypeArguments

* Accept new baselines

* Add tests
2022-12-07 10:06:12 -08:00
Anders Hejlsberg c07f51242c Fix narrowing by typeof applied to discriminant property (#51720)
* Fix narrowing by typeof applied to discriminant property

* Include effects of getReferenceCandidate

* Add tests
2022-12-05 11:51:54 -08:00
Anders Hejlsberg 8036b149a4 Fix isUnitLikeType to (again) handle tagged literal types (#51545)
* Fix isUnitLikeType to (again) handle tagged literal types

* Add regression test
2022-11-30 13:30:52 -08:00
Anders Hejlsberg cee6366c48 Fix isTypeDerivedFrom to properly handle {} and intersections (#51631)
* Fix isTypeDerivedFrom to properly handle {} and intersections

* Add tests
2022-11-29 08:29:35 -08:00
Anders Hejlsberg 7b85cd6b72 Numeric literals assignable to enum literals only when values match (#51561)
* Numeric literal assignable to enum literal only when values match

* Accept new baselines

* Update compiler sources

* Accept new baselines

* Fix test runner

* Any numeric literal type is assignable to a computed numeric enum type
2022-11-16 18:56:01 -08:00
Anders Hejlsberg f0216e3421 Improve reduction of similar intersections in type inference (#51405)
* Change criteria for reducing intersections in type inference

* Add regression test
2022-11-04 17:04:05 -07:00
Anders Hejlsberg 7cf842b42b Enum unification and improvements (#50528)
* Fix enum classification and evaluation

* References in literal enums must be to other enum members

* Accept new baselines

* Unify enum types + template literal constant expressions

* Accept new baselines

* Fix fourslash tests

* Fix new compiler errors

* Fix lint error

* Accept new API baselines

* Fix test

* Better error message + consistently check enum initializers

* Accept new baselines
2022-11-03 11:05:42 -07:00
Anders Hejlsberg 906ebe4933 Revert structuredTypeRelatedTo change and fix isUnitLikeType (#51076)
* Revert structuredTypeRelatedTo change, fix isUnitLikeType

* Accept new baselines

* Add regression tests

* Fix formatting in test
2022-10-19 15:46:00 -07:00
Anders Hejlsberg 37317a208f Check nested weak types in intersections on target side of relation (#51140)
* Check nested weak types in intersections on target side of relation

* Add regression tests

* Move logic from isRelatedTo to structuredTypeRelatedTo

* Fix lint error

* Add additional test
2022-10-13 08:20:07 -07:00
Anders Hejlsberg 4f54e7e947 Fix isExhaustiveSwitchStatement to better handle circularities (#51095)
* Fix isExhaustiveSwitchStatement to better handle circularities

* Add regression test
2022-10-12 07:22:06 -07:00
Anders Hejlsberg d06a592d02 Properly defer resolution of mapped types with generic as clauses (#51050)
* Fix isGenericMappedType, getTemplateLiteralType, getStringMappingType

* Accept new baselines

* Add regression tests

* Fix comment
2022-10-07 07:25:57 -07:00
Anders HejlsbergandMateusz Burzyński 96894db6cb Include type parameter defaults in contextual typing (#50994)
* Include type parameter defaults in contextual typing

* Add tests

* Add additional an test for instantiating contextual signature using default type param (#51002)

* Update comment

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2022-09-30 07:02:22 -07:00
Anders Hejlsberg ecf50e81a7 Properly compute SymbolFlags.Optional for intersected properties (#50958)
* `in` proves property presence only if property can't be undefined

* Accept new baselines

* Add tests

* Accept new baselines

* Properly compute SymbolFlags.Optional for intersected properties

* Accept new baselines

* Check optionality only for property-like declarations

* Add more tests
2022-09-29 15:18:21 -07:00
Anders Hejlsberg 01054e05ab Consistently add undefined/missing to optional tuple element types (#50831)
* Consistently add undefined/missing type to optional tuple elements

* Accept new baselines

* Add regression test
2022-09-20 18:14:20 -07:00
Anders Hejlsberg a11c41621b Improve checking of in operator (#50666)
* Improve checking of `in` operator

* Accept new baselines

* Add tests

* Delete old and accept new baselines

* Disallow right operand of type '{}'

* Accept new baselines

* Support number and symbol literals

* Add tests

* Disallow {} typed right operand only in strictNullChecks mode

* Accept new baselines

* Detect {} resulting from intersections

* Accept new baselines

* Don't attempt to reduce intersections with Record<K, unknown>

* Accept new baselines

* Return undefined instead of unknownSymbol from getGlobalRecordSymbol()
2022-09-19 14:16:01 -07:00
Anders Hejlsberg 3b84f76fb2 Fix crash caused by incorrect bounds check (regression in 4.8) (#50797)
* Fix bounds check

* Add regression test
2022-09-16 07:14:14 -07:00
Anders Hejlsberg 4110b80fbb Fix equality narrowing and comparable relation for intersections with {} (#50735)
* Fox equality narrowing and comparable relation for intersections with {}

* Accept new baselines

* Add tests

* Accept new baselines
2022-09-14 09:19:36 -07:00
Anders Hejlsberg 60963d7216 Discriminant of type never should never be matched (#50755)
* Discriminant of type 'never' should never be matched

* Add tests
2022-09-13 10:29:50 -07:00
Anders Hejlsberg a70bb9d3ff Preserve special intersections in mapped types (#50704)
* Preserve special intersections in mapped types

* Add regression test
2022-09-09 12:09:50 -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
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
Anders Hejlsberg 43f8ae6df4 Only normalize intersections that include {} (#50535)
* Only normalize intersections that include {}

* Accept new baselines
2022-08-31 14:36:03 -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
Anders Hejlsberg 6e8337ef70 Optimize substitution types (#50397)
* Optimize substitution type infrastructure

* Accept new baselines

* Preserve instantiated substitution types for type variables

* Restrictive type parameters should have no constraint

* Fix issues from top100 test run

* Accept new baselines
2022-08-26 12:06:06 -07:00
Anders Hejlsberg 697935da47 Restore ordering of operations involving type parameters and unions (#50116) 2022-08-03 00:32:41 -04:00
Anders Hejlsberg a4507c9225 Favor asserted type in type predicate narrowing (#50044)
* Favor asserted type in type predicate narrowing

* Accept new baselines
2022-07-26 17:39:35 -07:00
Anders Hejlsberg 4026c6fd80 Properly handle null and undefined in getCommonSupertype (#50021)
* Properly handle null and undefined in getCommonSupertype

* Add tests

* Add more tests
2022-07-24 08:09:14 -07:00
Anders Hejlsberg 2c68ded954 Improve narrowing logic for instanceof, type predicate functions, and assertion functions (#49625)
* Improve narrowing logic for instanceof, type predicates, and assertions

* Accept new baselines

* Add tests

* Tweak algorithm

* Accept new baselines

* Optimize for discriminated unions
2022-07-15 14:01:55 -10:00
Anders Hejlsberg c2897189cb Defer types like keyof (T & {}) (#49696)
* 'keyof undefined' and 'keyof null same as 'keyof never'

* Update tests

* Defer types like `keyof (T & {})`

* Restore test

* Update test

* Accept new baselines

* Add tests
2022-07-07 11:54:22 -10:00
Anders Hejlsberg 2eaf49f56e Handle pseudo-references in getFlowCacheKey (#49828)
* Handle pseudo-references in getFlowCacheKey

* Add tests

* Accept new baselines
2022-07-07 11:53:30 -10:00
Anders Hejlsberg 2f260885cc Cache results of expensive repetitive type operations (#49760) 2022-07-05 07:02:32 -10:00
Anders Hejlsberg 529ba99e29 Use separate marker types for variance annotation validation (#49616)
* Use separate marker types for variance annotation validation

* Add regression test
2022-06-21 06:42:10 -07:00
Anders Hejlsberg 18ac37221b Properly re-scan > token in type argument list determination logic (#49560)
* Properly re-scan '>' token in type argument list determination logic

* Add regression test
2022-06-15 12:06:08 -07:00
Anders Hejlsberg dc6a80bd00 Fresh {} is subtype of object (#49503)
* Fresh {} is subtype of object

* Add regression test
2022-06-13 12:21:51 -07:00
Anders HejlsbergandDaniel Rosenwasser e6808c4290 Instantiation expression can be followed by line break or binary operator (#49353)
* Allow instantiation expression to be followed by let or interface on new line

* Add tests

* Update src/compiler/parser.ts

* Instantiation expressions followed by line breaks or binary operators

* Add more tests

* Accept new baselines

* Fix lint error

* Update fourslash test

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2022-06-10 10:26:42 -07:00
Anders Hejlsberg 7e4a96e2fa Revise and simplify CFA for typeof check expressions (#49422)
* Revise and simplify CFA for `typeof` check expressions

* Accept new baselines

* Add regression test

* Slight change to preserve type when related in both directions

* Add regression test

* Explain reasons for exact sequence of type checks
2022-06-08 11:30:28 -07:00
Anders Hejlsberg 565249fbbe Fix definite assignment analysis issue caused by x !== null checks (#49387)
* Check for non-intersected `undefined` type in definite assignment analysis

* Add regression test
2022-06-06 09:51:13 -07:00
Anders Hejlsberg 1beb1037c0 Fix check in isMappedTypeGenericIndexedAccess (#49341)
* Fix check in isMappedTypeGenericIndexedAccess

* Add regression tests
2022-06-01 10:01:56 -07:00
Anders Hejlsberg 3cdb8081f7 Use NonNullable<T> in more scenarios (#49330)
* Remove getFalsyFlags and improve getNonNullableType

* Apply getNonNullableType to left operand of || operator

* Accept new baselines

* Add tests
2022-05-31 17:05:33 -07:00
Anders Hejlsberg 51b346d65a Improve intersection reduction and CFA for truthy, equality, and typeof checks (#49119)
* Improve reduction of intersection types

* Accept new baselines

* Improve CFA for truthy, equality, and typeof checks

* Accept new baselines

* Remove special case for Function type

* Don't reduce intersections of form {...} & object

* Accept new baselines

* Anything is assignable to unknown-like union

* Accept new baselines

* Tweak subtype check

* Recombine unknown type from unknown-like union in more cases

* Display union origin only if it is shorter than union itself

* Accept new baselines

* Add tests

* Only attach origin type when it is shorter than union itself

* Specially preserve string & {}, number & {}, bigint & {}

* Accept new baselines

* Add additional tests

* Fix getNormalizedType and getNarrowableTypeForReference for intersections

* Switch NonNullable<T> to use T & {}

* Accept new baselines

* Use NonNullable<T> in place of anonymous T & {}

* Accept new baselines

* Add fourslash test

* More fourslash tests

* Fix getFalsyFlags handling of intersections

* Accept new baselines

* Add constraint to compareProperties type parameter

* Unconstrained type parameter not assignable to {} with strictNullChecks

* Accept new baselines
2022-05-27 14:02:54 -07:00
Anders Hejlsberg c592ee781d Instantiate original target type in substituteIndexedMappedType (#49205) 2022-05-23 11:07:33 -07:00
Anders Hejlsberg 38c14606b4 Fix blocking of recursive dependencies in getNarrowedTypeOfSymbol (#48941)
* Better blocking of recursive dependencies in getNarrowedTypeOfSymbol

* Add regression test
2022-05-03 14:20:35 -07:00
Anders Hejlsberg 787bb9ddb6 Improve support for numeric string types (#48837)
* Improve support for numeric string types

* Update test

* Add tests
2022-04-25 15:36:06 -07:00
Anders Hejlsberg 65f6cb23d3 Constraints for mapped types with filtering 'as' clauses (#48699)
* Constraints for mapped types with filtering 'as' clauses

* Add regression test
2022-04-18 14:24:22 -07:00