You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO: Use InferencePriority.NoConstraints for type parameters which are being used contravariantly/in a write-only context
11968
-
// (Or, ideally, some future InferencePriority.SuperConstraints should we start tracking them!)
11969
-
// As-is, this is unsound - it can be made stricter by replacing `instantiateType(root.trueType, combinedMapper)` with
11970
-
// `getintersectionType([instantiateType(root.trueType, combinedMapper), instantiateType(root.trueType, mapper)])` which
11971
-
// would preserve the type-parametery-ness of the check; but such a limitation makes this branch almost useless, as only
11967
+
// TODO:
11968
+
// As-is, this is effectively sound, but not particularly useful, thanks to all the types it wrongly rejects - only
11972
11969
// conditional types with effectively "independent" inference parameters will end up being assignable via this branch, eg
11973
11970
// `type InferBecauseWhyNot<T> = T extends (p: infer P1) => any ? T | P1 : never;`
11974
-
// contains a union in the `true` branch, and so while we can't confirm assignability to `P1`, we _could_ confirm assignability
11975
-
// to `T`.
11971
+
// contains a union in the `true` branch, and so while we can't confirm assignability to `P1`, we can confirm assignability to `T`.
11972
+
// A lenient version could be made by replacing `getintersectionType([instantiateType(root.trueType, combinedMapper), instantiateType(root.trueType, mapper)])`
11973
+
// with `instantiateType(root.trueType, combinedMapper)` which would skip checking aginst the type-parametery-ness of the check;
11974
+
// but such a change introduces quite a bit of unsoundness as we stop checking against the type-parameteryness of the `infer` type,
11975
+
// which in turn prevents us from erroring on, eg, unsafe write-position assignments of the constraint of the type.
11976
+
// To be correct here, we'd need to track the implied variance of the infer parameters and _infer_ appropriately (in addition to checking appropriately)
11977
+
// Specifically, we'd need to infer with `InferencePriority.NoConstraint` (or ideally a hypothetical `InferencePriority.SuperConstraint`) for contravariant types,
11978
+
// but continue using the constraints for covariant ones.
tests/cases/compiler/thisConditionalInferenceInClassBody.ts(10,27): error TS2345: Argument of type '"hi"' is not assignable to parameter of type 'Unwrap<this["prop"]>'.
2
+
Type '"hi"' is not assignable to type 'string & U'.
0 commit comments