Open
Description
Suggestion
π Search Terms
string prototype object number stringprototype
β Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
We're always seeing people writing String
, Number
, Object
, and so on, in places where they should be writing their primitive equivalents.
We should mark these as @deprecated
so that they show up with strikethroughs in the editor, and make new global interfaces named e.g. StringPrototype
so it's more clear what they're for.
/**
* @deprecated Use `string` when working with strings, or use `StringPrototype` to declare new string methods
*/
interface String {
For back compat, possibly forever, we'll need to declare these as
interface StringPrototype extends String { }
so that existing references to String["charAt"]
continue to work and so that other merges continue to function.
π Motivating Example
π» Use Cases
- New users coming to TS