TypeScript: Missing escape/unescape ?
TypeScript Version:
1.8 Code
var a = escape("&#");
var b = unescape(a);
Expected behavior: no error
Actual behavior: can not find name ‘escape’ can not find name ‘unescape’
by the way, typescript playground experience is terrible when use Microsoft Edge (input chinese charactors , click a new line , select code)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 17 (15 by maintainers)
The global
escapeandunescapeare deprecated, please useencodeURIinstead. see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape.If you want to use them, just add the definitions:
@mhegazy @RyanCavanaugh
escape/unescapeare useful exactly because they don’t support UTF-8.decodeURIComponent(escape(s))andunescape(encodeURIComponent(s))are, even if imperfect, very common and established “patterns” to decode / encode UTF-8 across all browsers including pretty ancient ones.In this repo, https://github.com/jecovier/vue-json-excel/blob/master/JsonExcel.vue#L175. To achieve feeding btoa with data contains special characters, it is necessary to use
unescape(encodeURIComponent(s))first.Makes me sad actually 🥲
My opinion is that it is a good compromise with #19299. Splitting the baby again with
window.escapefeels a bit anti the spirit. For greenfield development, people will (should) be none the wiser of AnnexB. Those supporting legacy code or wanting 👣 🔫 can do so with a little bit of work.window.escapemight appropriately annoy those proactively using 👣 🔫 but the poor souls trying to support there legacy code bases without a huge amount of friction would be disserviced.@k8w those pages used to refer to it being deprecated, and it was. It does not appear to be deprecated in the current standard though, and I can’t find a specific reference to why the change was made. I suspect they were retained in the specification to not break code, but you shouldn’t be using them for new code as they don’t handle Unicode URIs properly, and so IMO they are best to leave out and people can add them back in if they are supporting old code.
@mhegazy It seems nothing refer to that they are deprecated ?