facebook / facebook/flow

recreating overload when passing a function as parameter with generic

Offen
#128 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
wishlist
Vorherrschende Sprache
Rust
Sterne
22.3k
Forks
1.9k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

let's look the first example:

``` typescript
declare var promisify :
((func: (callback: (err: any, result: R) => void) => void) =>
(() => Promise)) &
((func: (a: A, callback: (err: any, result: R) => void) => void) =>
((a:A) => Promise)) &
((func: (a: A, b: B, callback: (err: any, result: R) => void) => void) =>
((a:A, b: B) => Promise));

declare var readfile:
(path: string, callback: (err: any, result: string) => void) => void;

var promisifiedReadFile = promisify(readfile);
```

in this example everything works fine `promisifiedReadFile` has type :

``` typescript
(path: string) => Promise
```

(even if 'type-at-pos' display strange type information but that's another story).

If I change the declaration of `readfile` to :

``` typescript
declare var readfile:
(path: string, options: any, callback: (err: any, result: string) => void) => void &
(path: string, callback: (err: any, result: string) => void) => void;
```

`promisifiedReadFile` will have the type :

``` typescript
(path: string, options: any) => Promise
```

If I change again the declaration of readfile to :

``` typescript
declare var readfile:
(path: string, callback: (err: any, result: string) => void) => void &
(path: string, options: any, callback: (err: any, result: string) => void) => void;
```

`promisifiedReadFile` type will be again :

``` typescript
(path: string) => Promise
```

Firstly this is inconsistant, order in intersection type should not matter, then the desired behavior in both case would be to obtain the type

``` typescript
(path: string) => Promise &
(path: string, options: any) => Promise
```

or shorter:

``` typescript
(path: string, options?: any) => Promise
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.