The following code doesn’t work:
import * as blessed from "blessed" const mainScreen: Screen = blessed.screen({})
I get a type error from Typescript, which is:
fack.ts:4:7 - error TS2739: Type 'Screen' is missing the following properties from type 'Screen': availHeight, availWidth, colorDepth, orientation, pixelDepth 4 const mainScreen: Screen = blessed.screen({}) ~~~~~~~~~~
It looks like the Screen
type is incompatible with itself? How is this possible?
I’m using Node 14.15 and my dependency versions are:
{ "blessed": "^0.1.81", "@types/blessed": "^0.1.17" }
Why doesn’t this pass type checking?
Advertisement
Answer
When you see this sort of error it’s almost always because you have two types from two different packages which just so happen to share the same name. Here you have a function which returns a type blessed.Widgets.Screen
and you are assigning it to the type Screen
which is included in the global namespace by the typescript DOM typings.
Since your Screen
is the one from “blessed” rather than the one from the DOM, you need to import the type definition from the blessed package.
import * as blessed from "blessed" import {Widgets} from "blessed"; const mainScreen: Widgets.Screen = blessed.screen({});