Skip to content

bug(overlay): Compiler error using OverlayRef when implementing ScrollStrategy's attach method when in strict mode #25650

Closed
@mrahhal

Description

@mrahhal

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

13.x

Description

A related issue but the reporter was using PositionStrategy which for some reason works even in strict mode: #25098

This issue is describing another issue that occurs when trying to implement ScrollStrategy in strict mode. You can't use OverlayRef as that will lead to the compiler error shown below. A workaround is to use any instead.

Reproduction

Steps to reproduce:

  1. Set strict mode to true in tsconfig
  2. Try to implement ScrollStrategy using OverlayRef

Repro on StackBlitz

(On StackBlitz I noticed when opening the link I sometimes have to set strict to false then back to true for the problem to appear)

Expected Behavior

Either OverlayReference should be exported, or at least it should be compat with OverlayRef even in strict mode in ScrollStrategy.
Also it's a bit confusing when you look at the attach signature (or you run the "Implement interface" action) and you find OverlayReference which can't be imported. There's no easy way to tell you actually need to change it to OverlayRef. This should be somehow documented on the method.

Actual Behavior

We get the following compiler error:

Property 'attach' in type 'Some' is not assignable to the same property in base type 'ScrollStrategy'.
  Type '(overlayRef: OverlayRef) => void' is not assignable to type '(overlayRef: OverlayReference) => void'.
    Types of parameters 'overlayRef' and 'overlayRef' are incompatible.
      Type 'OverlayReference' is missing the following properties from type 'OverlayRef': _portalOutlet, _host, _pane, _config, and 29 more.

Environment

  • Angular: 14.2.2
  • CDK/Material: 14.2.2
  • Browser(s): Irrelevant
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

ng version:

Angular CLI: 14.2.3
Node: 18.4.0 (Unsupported)
Package Manager: npm 8.12.1
OS: win32 x64

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/overlay

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions