Skip to content

Typing inline generic operators seems much more annoying with 3.8 (coming from 3.6) #2161

@dmrickey

Description

@dmrickey

Let me know if I'm overcomplicating something. This is what we used to have in 3.6

const isTrailer = info.contentTypeId === ContentType.Trailer.id;
const insert = (item) => iif(isTrailer, insertItem(item), append([item]));
setState(
    patch({
        currentTranslations: insert(currentTranslation),
        defaultTranslations: insert(defaultTranslation),
        informationCollection: insert(info),
    })
);

for 3.8 this is what I've got to do now which seems needlessly verbose

const insert = <T extends SessionInformation | SessionTranslation>(item: T) =>
    iif(isTrailer, insertItem<T>(item as NoInfer<T>), append<T>([item] as NoInfer<T[]>));

Is there something I'm missing here or is it this complex now?

A couple more examples

const move = (collection: Array<SessionTranslation | SessionInformation>) => {
     const item = collection.find((x) => x.id === id);
     const index = collection.indexOf(item);
     return iif(index >= 0 && !!item, compose(removeItem(index), insertItem(item, 0)));
};
// to
const move = <T extends SessionInformation | SessionTranslation>(collection: Array<T>) => {
    const item = collection.find((x) => x.id === id);
    const index = collection.indexOf(item);
    return iif(index >= 0 && !!item, compose(removeItem<T>(index), insertItem<T>(item as NoInfer<T>, 0)));
};
const patchSeries = () => updateManyItems(() => true, patch({ isActive: content.isActive, isPublic: content.isPublic }));
setState(
    patch({
        showSeriesInformationCollection: patchSeries(),
    })
);
// to just doing it inline instead of having the self-documenting function name
setState(
    patch({
        showSeriesInformationCollection: updateManyItems(
            () => true,
            patch({ isActive: content.isActive, isPublic: content.isPublic })
        ),
    })
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions