microsoft / microsoft/TypeScript

int32 type returned by bitwise operators

Offen
#32,188 10 Kommentare 7 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

Search Terms

bitwise operators, integer type, int32

Suggestion

Add an int32 subtype for number returned by TypeScript from bitwise operators.

function coerce(n: number): int32 {
  return n | 0;
}

JavaScript bitwise operators coerce arguments to int32 and the return type of those operators will always be an int32.

This would not be a breaking change since int32 would be a subtype of number. Only bitwise operations would change to return int32s.

EDIT: I now recommend calling the type BitwiseInt32 so that user’s won’t see the type as a generic integer type.

Use Cases

Helps applications which are trying to take advantage of JavaScript implementations int32 optimizations. An application could ask for an int32 parameter to force coercion with n | 0.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Lies zunächst das vorgeschlagene Verhalten von int32/BitwiseInt32 und die verknüpfte ECMAScript-Spezifikation für Bitwise-Operatoren. Verfolge, wie TypeScript die Rückgabetypen von Bitwise-Operatoren darstellt, und prüfe das coerce-Beispiel. Erledigt ist die Aufgabe, wenn Bitwise-Operatoren den vorgeschlagenen Subtyp offenlegen und weiterhin number zugewiesen werden können und Design und Benennung geklärt sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.