microsoft / microsoft/TypeScript

Change return type of `Object` call signature to `unknown` (currently `any`)

Aperta
#57,379 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
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

https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwAowAjALniIEp4BeAPngGcMYtUBzaygNxyzAA3ACgRiQjSEB6afECg5PACiADwAO4DCGDw4zZBAyUQMGDhjjJNekwBEt6jLmLVGzNt0h9hyqhzwTMwsJYmtGeFQDCEdZBWV1TQ89AyMA03NLYgBvAF9qWJcE9x1knzSgzKIAZTYObic410SSrxTff0CMkKIAOWQAW1ITGOd4ty0W71TOi0qAeVIAK00R+EAZcjHmzynjdIsgA

💻 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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.