ant-design: Type error: Cannot find name 'ResizeObserver'.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

3.11.0

Environment

MacOs10.13.5 (17F77)

Reproduction link

https://github.com/ant-design/ant-design/blob/master/components/input/TextArea.tsx#L46 Sandbox

Steps to reproduce

  • create project
  • npm install typescript antd …
  • create index.tsx
  • npm start

What is expected?

success to start dev server

What is actually happening?

Type error: Cannot find name ‘ResizeObserver’.


The bug is caused by this pr

The compiled typings file antd/lib/input/TextArea.d.ts no import ResizeObserver

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 13
  • Comments: 34 (7 by maintainers)

Most upvoted comments

The temporary fix is putting following interface to your typings/index.d.ts:

interface ResizeObserver {
  observe(target: Element): void;
  unobserve(target: Element): void;
  disconnect(): void;
}

Temp fix:

  1. Open: node_modules/antd/lib/input/TextArea.d.ts
  2. Insert import: import ResizeObserver from 'resize-observer-polyfill';

+1

https://github.com/que-etc/resize-observer-polyfill/pull/45 fixes the polyfill’s types, but antd itself can be fixed by adding a /// <reference types="resize-observer-polyfill" /> to the file (to make the dependency on the global patch explicit), as an alternative.