Skip to content

Let the type of sources in watch always be a tupel #2655

Closed
@JensDll

Description

@JensDll

What problem does this feature solve?

When watching multiple sources you don't have to do explicit const assertion on the input array.

What does the proposed API look like?

Since TypeScript 4.0 and the ability to use generics in the tupel spread syntax, the sources parameter in watch can always be made a tupel type. Basically change the type of sources from T to readonly [...T]:

function watch<
  T extends Readonly<Array<WatchSource<unknown> | object>>,
  Immediate extends Readonly<boolean> = false
>(
  sources: T,
  cb: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>,
  options?: WatchOptions<Immediate>
): WatchStopHandle

// ----->

function watch<
  T extends Readonly<Array<WatchSource<unknown> | object>>,
  Immediate extends Readonly<boolean> = false
>(
  sources: readonly [...T],
  cb: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>,
  options?: WatchOptions<Immediate>
): WatchStopHandle

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions