microsoft / microsoft/TypeScript
No warning when using unary +/- operators on functions and objects?
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 2.6.1
Code
let func = () => "func";
+func; // no error
-func; // no error
let obj = { foo: "bar" };
+obj; // no error
-obj; // no error
Expected behavior:
Unary + or - is only applicable to a number or maybe a string. I would expect the lines listed as // no error to be errors.
Actual behavior:
Unary + and - never generates a warning no matter what crazy stuff I try to apply it to.
I was made aware of this behavior by a recent Stack Overflow question. I see from #7019 that unary + and - on strings is supported, and I guess I can understand that as a way to parse a string into a number (for +, anyway. Is - really used like this in practice?). But functions? objects? Seems more likely to be an error than intentional to me. Thoughts?
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
Riproduci l’esempio TypeScript 2.6.1 e confronta le diagnosi per + e - unari su funzioni, oggetti e stringhe. Esamina il comportamento esistente del controllo dei tipi degli operatori unari; il lavoro è completo quando gli operandi non validi previsti producono errori, mentre il comportamento supportato per le stringhe rimane intenzionale ed è coperto dai test.
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