@@ -22,6 +22,8 @@ pub struct CompatChecker<'a, R: TypeResolver = NoopResolver> {
2222 strict_null_checks : bool ,
2323 no_unchecked_indexed_access : bool ,
2424 exact_optional_property_types : bool ,
25+ /// When true, enables additional strict subtype checking rules for lib.d.ts
26+ strict_subtype_checking : bool ,
2527 cache : FxHashMap < ( TypeId , TypeId ) , bool > ,
2628}
2729
@@ -36,6 +38,7 @@ impl<'a> CompatChecker<'a, NoopResolver> {
3638 strict_null_checks : true ,
3739 no_unchecked_indexed_access : false ,
3840 exact_optional_property_types : false ,
41+ strict_subtype_checking : false ,
3942 cache : FxHashMap :: default ( ) ,
4043 }
4144 }
@@ -52,6 +55,7 @@ impl<'a, R: TypeResolver> CompatChecker<'a, R> {
5255 strict_null_checks : true ,
5356 no_unchecked_indexed_access : false ,
5457 exact_optional_property_types : false ,
58+ strict_subtype_checking : false ,
5559 cache : FxHashMap :: default ( ) ,
5660 }
5761 }
@@ -91,6 +95,18 @@ impl<'a, R: TypeResolver> CompatChecker<'a, R> {
9195 }
9296
9397 /// Configure strict mode for `any` propagation.
98+
99+ /// Configure strict subtype checking mode for lib.d.ts type checking.
100+ ///
101+ /// When enabled, applies additional strictness rules that reject borderline
102+ /// cases allowed by TypeScript's legacy behavior. This includes disabling
103+ /// method bivariance for soundness.
104+ pub fn set_strict_subtype_checking ( & mut self , strict : bool ) {
105+ if self . strict_subtype_checking != strict {
106+ self . strict_subtype_checking = strict;
107+ self . cache . clear ( ) ;
108+ }
109+ }
94110 ///
95111 /// When strict mode is enabled, `any` does NOT silence structural mismatches.
96112 /// This means the type checker will still report errors even when `any` is involved,
@@ -235,6 +251,8 @@ impl<'a, R: TypeResolver> CompatChecker<'a, R> {
235251 self . subtype . exact_optional_property_types = self . exact_optional_property_types ;
236252 self . subtype . strict_null_checks = self . strict_null_checks ;
237253 self . subtype . no_unchecked_indexed_access = self . no_unchecked_indexed_access ;
254+ // In strict mode, disable method bivariance for soundness
255+ self . subtype . disable_method_bivariance = self . strict_subtype_checking ;
238256 }
239257
240258 fn violates_weak_type ( & self , source : TypeId , target : TypeId ) -> bool {
0 commit comments