-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript incorrectly handles naughty strings in json #53519
Comments
I mean it seems to me like the purpose of the warning is precisely because the compiler won’t be able to handle the file correctly otherwise… |
Typescript expects JavaScript or TypeScript code, you are providing it json which is not a valid JavaScript or TypeScript input, as JSON allows raw characters that are not allowed in JavaScript and TypeScript. If you do not want to encode your JSOn input into a valid JavaScript/TypeScript input, place it in a seperate .json file and import it |
Not the case anymore after https://github.com/tc39/proposal-json-superset—all JSON are now valid ES expressions, including unescaped LS and PS in string literals. |
Can we use more technically-precise terminology than "bad" or "naughty" ? What is the nature of the strings that aren't handled correctly? |
@RyanCavanaugh The buggy code reported here has exactly one problem: const myjson = [
"
test
",
] as const; This string has a U+2029 Paragraph Separator character on both ends. After JSON-superset, this should be valid ES code, but seems the TS lexer is not updated yet. I assume the same error would occur with U+2028 Line Separator. |
…in string literal
…ph and line separators in string literal
A new `lint:tsc` command has been added to validate TypeScript types in the project. This lint command uses a separate configuration, `tsconfig.lint.ts`, which covers just the files that have no type errors. We can expand the type check coverage over time as we fix more type errors. One additional change was made to fix a TypeScript error that hade an impact on many files. The problem was caused by a TypeScript bug that causes the compiler to fail when it encounters certain unicode characters. Those characters were in a JSON file in the `unicode-confusables` package. They have been temporarily removed until this TypeScript error can be fixed. For more details, see microsoft/TypeScript#53519
A new `lint:tsc` command has been added to validate TypeScript types in the project. This lint command uses a separate configuration, `tsconfig.lint.ts`, which covers just the files that have no type errors. We can expand the type check coverage over time as we fix more type errors. One additional change was made to fix a TypeScript error that hade an impact on many files. The problem was caused by a TypeScript bug that causes the compiler to fail when it encounters certain unicode characters. Those characters were in a JSON file in the `unicode-confusables` package. They have been temporarily removed until this TypeScript error can be fixed. For more details, see microsoft/TypeScript#53519
A new `lint:tsc` command has been added to validate TypeScript types in the project. This lint command uses a separate configuration, `tsconfig.lint.ts`, which covers just the files that have no type errors. We can expand the type check coverage over time as we fix more type errors. One additional change was made to fix a TypeScript error that hade an impact on many files. The problem was caused by a TypeScript bug that causes the compiler to fail when it encounters certain unicode characters. Those characters were in a JSON file in the `unicode-confusables` package. They have been temporarily removed until this TypeScript error can be fixed. For more details, see microsoft/TypeScript#53519
A new `lint:tsc` command has been added to validate TypeScript types in the project. This lint command uses a separate configuration, `tsconfig.lint.ts`, which covers just the files that have no type errors. We can expand the type check coverage over time as we fix more type errors. One additional change was made to fix a TypeScript error that hade an impact on many files. The problem was caused by a TypeScript bug that causes the compiler to fail when it encounters certain unicode characters. Those characters were in a JSON file in the `unicode-confusables` package. They have been temporarily removed until this TypeScript error can be fixed. For more details, see microsoft/TypeScript#53519
Bug Report
🔎 Search Terms
bad naughty json string
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
When you enter the playground, an alert message will appear:
Click at 'Cancel', otherwise, you'll not see the errors at the errors tab.
💻 Code
Code here will tell you nothing, you should see the playground above. Don't worry, it's not complicated at all.
🙁 Actual behavior
There are several errors reported by the compiler, you can see them in the image below:
🙂 Expected behavior
I believe the compiler should be able to correctly handle these potencial problematic strings.
The text was updated successfully, but these errors were encountered: