You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript Version: 2.1.1 (what's running on the playground)
Code
This works
interfaceData{a?: "a"|"b",b: number,c: "a"|"b"}typePatch=Partial<Data>functioncopyFields(target: Data,source: Patch): Data{for(letidinsource){target[id]=source[id];}returntarget;}functionmakesrc(): Data{return{b: 1,c: "a"}}/*1*/copyFields(makesrc(),{d: "d"});//Should (and does) give an error/*2*/copyFields(makesrc(),{a: "d"});//Should (and does) give an error/*3*/copyFields(makesrc(),{c: "d"});//Should (and does) give an error//I don't want to specify all the source properties /*4*/copyFields(makesrc(),{b: 2});//Should not (and doesn't) give an error/*5*/copyFields(makesrc(),{a: "b"});//Should not (and doesn't) give an error
But the generic version doesn't
interfaceData{a?: "a"|"b",b: number,c: "a"|"b"}functioncopyFields<T>(target: T,source: Partial<T>): T{for(letidinsource){target[id]=source[id];}returntarget;}functionmakesrc(): Data{return{b: 1,c: "a"}}/*1*/copyFields(makesrc(),{d: "d"});//Should (and does) give an error/*2*/copyFields(makesrc(),{a: "d"});//Should (and does) give an error/*3*/copyFields(makesrc(),{c: "d"});//Should (BUT DOES NOT) give an error//I don't want to specify all the source properties /*4*/copyFields(makesrc(),{b: 2});//Should not (and doesn't) give an error/*5*/copyFields(makesrc(),{a: "b"});//Should not (BUT DOES) give an error
I expected no change in type safety in the generic version.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.1.1 (what's running on the playground)
Code
This works
But the generic version doesn't
I expected no change in type safety in the generic version.
The text was updated successfully, but these errors were encountered: