typescript-fsa icon indicating copy to clipboard operation
typescript-fsa copied to clipboard

Success results are always optional now

Open jollytoad opened this issue 7 years ago • 2 comments

Hi, I've just tried updating to TS 3.0.1 and ts-fsa 3.0.0-beta-2, i previously had this generic reducer...

const mergeResultIntoIndex = <T extends Identified>(state: Indexed<T>, {result}: Success<any, T>): Indexed<T> => {
    return {
        ...state,
        [result.id]: result
    }
}

where:

export interface Identified {
    readonly id: string
}

export type Indexed<V> = { [id: string]: V }

but now i'm seeing the error:

TS2418: Type of computed property's value is 'T | undefined', which is not assignable to type 'T'.

for the line:

        [result.id]: result

jollytoad avatar Aug 24 '18 09:08 jollytoad

I should say, I was on TS 2.9.2 & ts-fsa 2.5.0 previously.

jollytoad avatar Aug 24 '18 09:08 jollytoad

Thanks for your report. Looks like the typings of 3.0.0-beta-2 don't handle this case well.

Meanwhile, you can use [email protected].

aikoven avatar Aug 27 '18 05:08 aikoven