utils/customError: narrow type of name property

The name property is inherited from Error and has a type of string.
But our CustomError ensures that the name is restricted to the type
of T. This causes compiler errors, so we had to enable a babel plugin
to support it.
This commit is contained in:
David Lechner
2022-05-20 16:46:17 -05:00
parent 348d6e90d9
commit 4e88605b16
3 changed files with 10 additions and 1 deletions
+5 -1
View File
@@ -16,7 +16,11 @@ const hasJsxRuntime = (() => {
})();
module.exports = babelJest.createTransformer({
plugins: ['@shopify/react-i18n/babel'],
plugins: [
['@babel/plugin-transform-typescript', {
allowDeclareFields: true
}],
'@shopify/react-i18n/babel'],
presets: [
[
require.resolve('babel-preset-react-app'),
+3
View File
@@ -427,6 +427,9 @@ module.exports = function (webpackEnv) {
],
plugins: [
[require.resolve('@babel/plugin-transform-typescript'), {
allowDeclareFields: true
}],
require.resolve('@shopify/react-i18n/babel'),
isEnvDevelopment &&
shouldUseReactRefresh &&
+2
View File
@@ -2,6 +2,8 @@
// Copyright (c) 2022 The Pybricks Authors
export class CustomError<T extends string> extends Error {
declare name: T;
public constructor(name: T, message: string, cause?: Error) {
super(message, { cause });
this.name = name;