microsoft / microsoft/TypeScript
Change return type of `Object` call signature to `unknown` (currently `any`)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
ObjectConstructor, Object, assignable, function
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about 5.3.3
⏯ Playground Link
💻 Code
declare function foo(cb: () => string): void;
foo();// ✅ Expected result: error
foo(() => "");// ✅ Expected result: no error
foo(() => null);// ✅ Expected result: error
foo({})// ✅ Expected result: error
foo(String);// ✅ Expected result: no error
foo(Number);// ✅ Expected result: error
foo(Object);// ❌ Expected result: error
🙁 Actual behavior
Object (ObjectContructor) is assignable to any function, because it has a callable signature with return type of any.
This lets the developers to use Object where only a properly typed function would be allowed, which can lead to unexpected runtime errors.
I know this is a pretty edge case, but in my opinion it's worth looking into.
🙂 Expected behavior
Object is not assignable to functions with different return type
Additional information about the issue
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground example and the ObjectConstructor call signature described in the issue. Check how changing its return type from any to unknown affects assignability, then verify that Object is rejected for the shown string-returning callback while the other examples retain their expected results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100