Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned object is not assignable to defined return type #153

Closed
zaunermax opened this issue Oct 29, 2020 · 3 comments
Closed

Returned object is not assignable to defined return type #153

zaunermax opened this issue Oct 29, 2020 · 3 comments
Assignees
Labels
limitation We're limited here question More info is requested wiki It's nice to learn stuff

Comments

@zaunermax
Copy link

馃悶 Bug Report

Describe the bug

I seem to run into a bug, where Update works flawlessly on static types, but breaks on generic types.

Reproduce the bug

enum TypeEnum {
	FOO = 'foo',
	BAR = 'bar',
}

type HasCompany = { company: { type: string } };
type UpdatedHasCompany = Object.P.Update<HasCompany, ['company', 'type'], TypeEnum>;

// this works flawlessly
const test: UpdatedHasCompany = { company: { type: TypeEnum.BAR } };

// this does not work!
const updateType = <T extends HasCompany>(
	e: T,
): Object.P.Update<T, ['company', 'type'], TypeEnum> => ({
	...e,
	company: {
		type: TypeEnum.BAR, // here i would have a conversion function
	}
});

Expected behavior

P.Update should work with generics. Not sure if this is a TS limitation though 馃

Additional context

toolbelt version 8.0.7 - Typescript version 4.0.3

@millsp millsp self-assigned this Oct 30, 2020
@millsp millsp added bug Something isn't working enhancement Improving something limitation We're limited here and removed bug Something isn't working labels Oct 30, 2020
@millsp millsp changed the title Object.P.Update does not seem to work with genercis Returned object is not assignable to defined return type Oct 30, 2020
@millsp
Copy link
Owner

millsp commented Oct 30, 2020

Hey @zaunermax, thanks for reporting this. This is a limitation where TypeScript is not able to predict the output in the presence of a generic type. You will have to override and cast your returned value to any.

@millsp millsp closed this as completed Oct 30, 2020
@zaunermax
Copy link
Author

Ok thanks for clarifying, sorry to having bothered you 馃檶

@millsp millsp added question More info is requested wiki It's nice to learn stuff labels Oct 30, 2020
@millsp
Copy link
Owner

millsp commented Oct 30, 2020

My pleasure, no problem. I'm adding this to the wiki.

Cheers

@millsp millsp removed the enhancement Improving something label Oct 30, 2020
Repository owner locked and limited conversation to collaborators Feb 2, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
limitation We're limited here question More info is requested wiki It's nice to learn stuff
Projects
None yet
Development

No branches or pull requests

2 participants