TypeScript Version: 3.3.0-dev.20181121
Search Terms: function types, return types, inconsistent
Code
consttest={1: '',2: '',3: ''};typekeys={[keyinkeyoftypeoftest]: string};typeStateFunction<TState>=()=>TState;consta: StateFunction<keys>=()=>({ ...test,4: ''});//Does not errorconstb=(): keys=>({ ...test,4: ''});//Errors properlyExpected behavior:
const a: StateFunction<keys> = () => ({ ...test, 4: '' }); Should error
Actual behavior:
const a: StateFunction<keys> = () => ({ ...test, 4: '' }); Does not error
Playground Link:http://www.typescriptlang.org/play/#src=const%20test%20%3D%20%7B%201%3A%20''%2C%202%3A%20''%2C%203%3A%20''%20%7D%3B%0D%0A%0D%0Atype%20keys%20%3D%20%7B%20%5Bkey%20in%20keyof%20typeof%20test%5D%3A%20string%20%7D%3B%0D%0Atype%20StateFunction%3CTState%3E%20%3D%20()%20%3D%3E%20TState%3B%0D%0A%0D%0Aconst%20a%3A%20StateFunction%3Ckeys%3E%20%3D%20()%20%3D%3E%20(%7B%20...test%2C%204%3A%20''%20%7D)%3B%0D%0A%0D%0Aconst%20b%20%3D%20()%3A%20keys%20%3D%3E%20(%7B%20...test%2C%204%3A%20''%20%7D)%3B
TypeScript Version: 3.3.0-dev.20181121
Search Terms: function types, return types, inconsistent
Code
Expected behavior:
const a: StateFunction<keys> = () => ({ ...test, 4: '' });Should errorActual behavior:
const a: StateFunction<keys> = () => ({ ...test, 4: '' });Does not errorPlayground Link:http://www.typescriptlang.org/play/#src=const%20test%20%3D%20%7B%201%3A%20''%2C%202%3A%20''%2C%203%3A%20''%20%7D%3B%0D%0A%0D%0Atype%20keys%20%3D%20%7B%20%5Bkey%20in%20keyof%20typeof%20test%5D%3A%20string%20%7D%3B%0D%0Atype%20StateFunction%3CTState%3E%20%3D%20()%20%3D%3E%20TState%3B%0D%0A%0D%0Aconst%20a%3A%20StateFunction%3Ckeys%3E%20%3D%20()%20%3D%3E%20(%7B%20...test%2C%204%3A%20''%20%7D)%3B%0D%0A%0D%0Aconst%20b%20%3D%20()%3A%20keys%20%3D%3E%20(%7B%20...test%2C%204%3A%20''%20%7D)%3B