dojo / core

:rocket: Dojo 2 - language helpers and utilities.
http://dojo.io
Other
213 stars 62 forks source link

Type updates for ExtensiblePromise and Task #257

Closed rorticus closed 7 years ago

rorticus commented 7 years ago

There were some issues with ExtensiblePromise and Task not returning the right types from then, resolve, and all.

This hopefully fixes those problems :)

codecov-io commented 7 years ago

Current coverage is 95.15% (diff: 100%)

Merging #257 into master will increase coverage by 0.13%

@@             master       #257   diff @@
==========================================
  Files            33         33          
  Lines          1788       1796     +8   
  Methods          17         17          
  Messages          0          0          
  Branches        348        348          
==========================================
+ Hits           1699       1709    +10   
+ Misses           28         27     -1   
+ Partials         61         60     -1   

Powered by Codecov. Last update df944e2...7cdfe1c

nicknisi commented 7 years ago

It looks like the catch signatures may need to be updated for Task as well.

import Task from 'dojo-core/async/Task';

// This one throws an error
// Type 'Task<void>' is not assignable to type 'Task<string>'. Type 'void' is not assignable to type 'string'.
export function returnString(): Task<string> {
    return Task.resolve(undefined)
        .then(() => 'hi')
        .catch(error => {
            // do nothing
        });
}

// no errors because it throws
export function returnString2(): Task<string> {
    return Task.resolve(undefined)
        .then(() => 'hi')
        .catch(error => {
            throw error;
        });
}

// no errors because it returns a string
export function returnString3(): Task<string> {
    return Task.resolve(undefined)
        .then(() => 'hi')
        .catch(error => {
            return 'bye';
        });
}
rorticus commented 7 years ago

@nicknisi I updated the catch types for Task as well.

nicknisi commented 7 years ago

Types are working better now! Thank you!