ui5-typescript icon indicating copy to clipboard operation
ui5-typescript copied to clipboard

@types/openui5 - missing type information for sap/ui/Device

Open marcelschork opened this issue 3 years ago • 2 comments

Tested with @types/openui5 version 1.96.0. image

marcelschork avatar Nov 25 '21 16:11 marcelschork

Thanks @marcelschork for reporting this issue.

An alternative with typing right now would be using the Device.browser API like this:

import { browser } from "sap/ui/Device";

const isMobile = browser.mobile;

petermuessig avatar Nov 28 '21 16:11 petermuessig

Hi Marcel, thanks for reporting. I can confirm that on Device basically nothing is defined. For the time being you can import the properties of Device, which are named exports:

import { browser } from "sap/ui/Device";

On those, everything you need should be defined.

akudev avatar Nov 28 '21 21:11 akudev

Hi Marcel,

@akudev and I recently "massaged" the types a bit more and we aligned the generated output with the expectation of the runtime. Starting with 1.115.0 onwards we provide type definitions which allow the usage of the Device API via:

import Device from "sap/ui/Device";

const isMobile = Device.browser.mobile;

or as dynamic import:

const Device = (await import("sap/ui/Device")).default;

const isMobile = Device.browser.mobile;

As said, this matches now the behavior of the runtime and types are only available at the default export and not as named exports anymore (except for libraries - but description will follow with the next release of the types).

Stay tuned for the next types release...

We close the issue now.

Cheers

petermuessig avatar May 25 '23 09:05 petermuessig