Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread operator should work with generic types #13557

Closed
falsandtru opened this issue Jan 18, 2017 · 13 comments
Closed

Spread operator should work with generic types #13557

falsandtru opened this issue Jan 18, 2017 · 13 comments
Labels
Duplicate An existing issue was already created

Comments

@falsandtru
Copy link
Contributor

TypeScript Version: master

Code

function f<a extends Object>() {
	return {...<a>{}};
}
function g<a extends object>() {
	return {...<a>{}};
}

Expected behavior:

ok

Actual behavior:

index.ts(2,10): error TS2698: Spread types may only be created from object types.
index.ts(5,10): error TS2698: Spread types may only be created from object types.

@HerringtonDarkholme
Copy link
Contributor

Another example, it's quite hard for TypeScript to prove a type constraint is spreadable given structural typing

class NonPrimitive {
    private cannotBePrimitiveBrand
}
function t<T extends NonPrimitive>(a: T, b: NonPrimitive) {
    var c = { ...a }
    var d = { ...b }
}

#2103 (comment)

@billba
Copy link
Member

billba commented Apr 24, 2017

Another example:

interface Foo {
    foo: string;
}

const addBar = <F extends Foo>(input: F) => ({
    ... input,
    bar: 5
});

Build 2.3.0-dev.20170424 gives error TS2698: Spread types may only be created from object types. on ...input,

@mhegazy
Copy link
Contributor

mhegazy commented Apr 24, 2017

Duplicate of #10727. Fixed by #13288

@mhegazy mhegazy closed this as completed Apr 24, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 24, 2017
@billba
Copy link
Member

billba commented Apr 24, 2017

@mhegazy This is still happening in the current build.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 24, 2017

yes. #13288 is not merged yet. we do not have an ETA at the moment.

@billba
Copy link
Member

billba commented Apr 24, 2017

Aha, thanks.

@LKay
Copy link

LKay commented Apr 25, 2017

When it will be fixed finally? The problem persists and it's breaking code all over the place!

@devlato
Copy link

devlato commented Apr 20, 2018

Any plans fixing this?

@massimonewsuk
Copy link

Is there a milestone or version that we can expect this to be fixed in?

@nblavoie
Copy link

Count me in !

@mcamou
Copy link

mcamou commented Jul 23, 2018

Any news on when/whether #13288 will be merged? This bug has been open for over a year now.

@ivansky
Copy link

ivansky commented Aug 23, 2018

@mhegazy
It's not a duplicate! I am interested in fixing too.
Could you remove label and reopen the issue?

@RyanCavanaugh
Copy link
Member

Please read #13288 (comment)

@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests