Comments (7)
It's probably time for my once-every-few-years attempt to look at #241 again and see what doesn't work these days
from typescript.
@essenmitsosse That is working as intended. The type of your variables inferred to { foo: string; bar: string }
due to the lack of type annotation, and when returning the value the compiler only checks compatibility. { foo: string; bar: string }
is compatible with the type { foo: string }
.
See the FAQ entry: (Indirect) Excess Properties Are OK
from typescript.
This is essentially a duplicate of #241. Check the linked issues.
from typescript.
Thanks for the reference @MartinJohns! My "Excess property checks on return types" search did not hit "widen return types" it seems 😂
But okay, great. I also see there was a design discussion on this #56965.
It seems it is planned to be fixed, hm
from typescript.
Okay, so I get a response that the referenced discussion (#56965) is related, but not a fix for this issue. So yeah, not sure how much attention this deserves and how to ensure it gets that deserved attention 🤔
from typescript.
Not sure if this is considered related, but this also doesn't work:
cbFunc<MyType>((): MyType => {
const value = {
foo: 'bar',
bar: 'baz'
}
return value
})
from typescript.
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- Variance annotations are not allowed in type aliases for intersections HOT 5
- No error or warning when assigning a constant to a constant but crash when run HOT 4
- Add support for Iterator Helpers (now stage 3) HOT 7
- Inconsistency between element access and object destruction HOT 1
- the union type bug? HOT 2
- Broken type inference for union of function and object HOT 2
- Symbol = LiveSymbol | DeadSymbol HOT 5
- compilerOptions.plugins accepts missing plugins without any logging or error information HOT 2
- Type inference considers only type amendments (if any are present), ignoring original typings HOT 4
- `satisfies` for return types HOT 5
- Type name in @throws not rendered as a link HOT 2
- Add organize imports presets
- Inconsistency between destructuring and object access in filter-narrowing. HOT 2
- autoimports crashes with aliased export
- Anonymous Function Type Not Constraining Object Return Value HOT 4
- Printer introduces syntax error into .tsx files
- Empty class type is satisfied by literally anything HOT 4
- The behavior of class Parameter Properties changes with the es target HOT 3
- Use-before-assignment check misses uses of vars defined in previous branch in switch HOT 2
- vscode should honor tsconfig.app.json - not just tsconfig.json HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.