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
typeA=()=>{b: number;c: number;}consta: A=()=>{return{b: 3,c: 4,d: 9,// no emit error, but must emit error};};consta2: ()=>{b: number;c: number;}=()=>{return{b: 3,c: 4,d: 9,// no emit error, but must emit error};};consta3=() : {b: number,c: number}=>{return{b: 3,c: 4,d: 9,// emit error, ok!};};
Expected behavior:
All three functions must emit error, because "d" field not exists in return type
Actual behavior:
Only last function emit error
Type '{ b: number; c: number; d: number; }' is not assignable to type '{ b: number; c: number; }'.
Object literal may only specify known properties, and 'd' does not exist in type '{ b: number; c: number; }'.
Environment
version
"typescript": "3.0.1",
tsconfig
json { "compilerOptions": { "target": "es6", "moduleResolution": "node", "noResolve": false, "sourceMap": true, "skipLibCheck": true, "strict": true, "noImplicitReturns": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es5", "es6", "es7", "es2015", "es2015.reflect", "es2015.symbol", "es2015.promise", "es2016", "es2016.array.include", "es2017", "dom", "dom.iterable" ], "jsx" : "react", "types": [ "jasmine" ] }, "exclude": [ "node_modules" ] }
Code
Expected behavior:
All three functions must emit error, because "d" field not exists in return type
Actual behavior:
Only last function emit error
Type '{ b: number; c: number; d: number; }' is not assignable to type '{ b: number; c: number; }'.
Object literal may only specify known properties, and 'd' does not exist in type '{ b: number; c: number; }'.
Playground Link: https://www.typescriptlang.org/play/#src=type%20A%20%3D%20()%20%3D%3E%20%7B%20b%3A%20number%3B%20c%3A%20number%3B%20%7D%20%0D%0Aconst%20a%3A%20A%20%20%3D%20()%20%3D%3E%20%7B%0D%0A%20%20return%20%7B%0D%0A%20%20%20%20b%3A%203%2C%0D%0A%20%20%20%20c%3A%204%2C%0D%0A%20%20%20%20d%3A%209%2C%0D%0A%20%20%7D%3B%0D%0A%7D%3B%0D%0A%0D%0Aconst%20a2%3A%20()%20%3D%3E%20%7B%20b%3A%20number%3B%20c%3A%20number%3B%20%7D%20%3D%20()%20%3D%3E%20%7B%0D%0A%20%20return%20%7B%0D%0A%20%20%20%20b%3A%203%2C%0D%0A%20%20%20%20c%3A%204%2C%0D%0A%20%20%20%20d%3A%209%2C%0D%0A%20%20%7D%3B%0D%0A%7D%3B%0D%0A%0D%0Aconst%20a3%20%3D%20()%20%3A%20%7B%20b%3A%20number%2C%20c%3A%20number%20%7D%20%3D%3E%20%7B%0D%0A%20%20return%20%7B%0D%0A%20%20%20%20b%3A%203%2C%0D%0A%20%20%20%20c%3A%204%2C%0D%0A%20%20%20%20d%3A%209%2C%0D%0A%20%20%7D%3B%0D%0A%7D%3B
The text was updated successfully, but these errors were encountered: