microsoft / microsoft/TypeScript
int32 type returned by bitwise operators
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza leyendo el comportamiento propuesto de int32/BitwiseInt32 y la especificación de ECMAScript vinculada sobre los operadores bit a bit. Rastrea cómo TypeScript representa los tipos de retorno de los operadores bit a bit y comprueba el ejemplo de coerce. Se considera terminado cuando los operadores bit a bit exponen el subtipo propuesto y siguen siendo asignables a number, con el diseño y la nomenclatura resueltos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100