Merge pull request #8982 from backstage/rugvip/tsbump
Upgrade TypeScript to 4.5 and decouple versioning
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
---
|
||||
'@backstage/cli': minor
|
||||
---
|
||||
|
||||
Removed the `typescript` dependency from the Backstage CLI in order to decouple the TypeScript version in Backstage projects. To keep using a specific TypeScript version, be sure to add an explicit dependency in your root `package.json`:
|
||||
|
||||
```json
|
||||
"dependencies": {
|
||||
...
|
||||
"typescript": "~4.5.4",
|
||||
}
|
||||
```
|
||||
|
||||
We recommend using a `~` version range since TypeScript releases do not adhere to semver.
|
||||
|
||||
It may be the case that you end up with errors if you upgrade the TypeScript version. This is because there was a change to TypeScript not long ago that defaulted the type of errors caught in `catch` blocks to `unknown`. You can work around this by adding `"useUnknownInCatchVariables": false` to the `"compilerOptions"` in your `tsconfig.json`:
|
||||
|
||||
```json
|
||||
"compilerOptions": {
|
||||
...
|
||||
"useUnknownInCatchVariables": false
|
||||
}
|
||||
```
|
||||
|
||||
Another option is to use the utilities from `@backstage/errors` to assert the type of errors caught in `catch` blocks:
|
||||
|
||||
```ts
|
||||
import { assertError, isError } from '@backstage/errors';
|
||||
|
||||
try {
|
||||
...
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
...
|
||||
// OR
|
||||
if (isError(error)) {
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
'@backstage/create-app': patch
|
||||
---
|
||||
|
||||
The app template has been updated to add an explicit dependency on `typescript` in the root `package.json`. This is because it was removed as a dependency of `@backstage/cli` in order to decouple the TypeScript versioning in Backstage projects.
|
||||
|
||||
To apply this change in an existing app, add a `typescript` dependency to your `package.json` in the project root:
|
||||
|
||||
```json
|
||||
"dependencies": {
|
||||
...
|
||||
"typescript": "~4.5.4",
|
||||
}
|
||||
```
|
||||
|
||||
We recommend using a `~` version range since TypeScript releases do not adhere to semver.
|
||||
|
||||
It may be the case that you end up with errors if you upgrade the TypeScript version. This is because there was a change to TypeScript not long ago that defaulted the type of errors caught in `catch` blocks to `unknown`. You can work around this by adding `"useUnknownInCatchVariables": false` to the `"compilerOptions"` in your `tsconfig.json`:
|
||||
|
||||
```json
|
||||
"compilerOptions": {
|
||||
...
|
||||
"useUnknownInCatchVariables": false
|
||||
}
|
||||
```
|
||||
|
||||
Another option is to use the utilities from `@backstage/errors` to assert the type of errors caught in `catch` blocks:
|
||||
|
||||
```ts
|
||||
import { assertError, isError } from '@backstage/errors';
|
||||
|
||||
try {
|
||||
...
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
...
|
||||
// OR
|
||||
if (isError(error)) {
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user