microsoft / microsoft/TypeScript
Change return type of `Object` call signature to `unknown` (currently `any`)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’esempio collegato di TypeScript Playground e con la firma di chiamata di ObjectConstructor descritta nell’issue. Verifica come cambia l’assegnabilità modificando il tipo restituito da any a unknown, quindi verifica che Object venga rifiutato per la callback mostrata che restituisce una stringa, mentre gli altri esempi mantengono i risultati attesi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100