ts-plus / typescript

Apache License 2.0
37 stars 5 forks source link

External definitions for ReadonlyArray don't work unless you type alias it, tag and import the alias #247

Closed patroza closed 1 year ago

patroza commented 1 year ago

ReadonlyArray is a problem too it seems, the one defined by TS, trying to use with:

    {
      "definitionName": "make",
      "definitionKind": "const",
      "extensions": [
        {
          "kind": "static",
          "typeName": "fp-ts/data/ReadonlyArray.Ops",
          "name": "make"
        }
      ]
    },

global:

declare global {
  /**
   * @tsplus type ReadonlyArray
   * @tsplus type Iterable
   * @tsplus companion fp-ts/data/ReadonlyArray.Ops
   * @tsplus companion ReadonlyArray.Ops
   */
  interface ReadonlyArray<T> {}
}
export const nea = ReadonlyArray.make(1)

error: ReadonlyArray' only refers to a type, but is being used as a value here. though maybe the companion trick only works via the json declaration?

It does work when I create a file and do this:

/**
 * @tsplus type ReadonlyArray
 * @tsplus type Iterable
 * @tsplus companion fp-ts/data/ReadonlyArray.Ops
 * @tsplus companion ReadonlyArray.Ops
 */
export type ROA<A> = ReadonlyArray<A>
export type { ROA as ReadonlyArray }

and then instead import from there

patroza commented 1 year ago

@0x706b this seems to work well now, thanks!