screepers/typed-screeps

Introduce some util types for writing test cases

DiamondMofeng opened this issue · 1 comments

Brief Description

I am tring to solve some issues like #219 and I am somewhat surprised by the existing test suite.

Coincidentally, I was recently playing the type-challenges. There are some util types (see https://github.com/type-challenges/type-challenges/blob/main/utils/index.d.ts) to check if the type inferred through our type definition is correct.

For both convenience and rigor, we could introduce some util types from it.

Sample code (if available)

export type Expect<T extends true> = T

export type Equal<X, Y> =
    (<T>() => T extends X ? 1 : 2) extends
    (<T>() => T extends Y ? 1 : 2) ? true : false
export type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true

//.........

const creep = Game.creeps['foo']

type cases = [
    Expect<Equal<typeof creep, Creep>>,

    //@ts-expect-error
    Expect<NotEqual<typeof creep, Creep>>,
]