-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3fe7e2
commit fe2e899
Showing
10 changed files
with
7,489 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# @total-typescript/error-translation-engine | ||
|
||
## 1.0.3 | ||
|
||
### Patch Changes | ||
|
||
- [#83](https://github.com/mattpocock/ts-error-translator/pull/83) [`6c29b64`](https://github.com/mattpocock/ts-error-translator/commit/6c29b640de019b59fe8c780a8cf139724a6c3efc) Thanks [@eddyw](https://github.com/eddyw)! - Correctly match duplicated matched parameters | ||
|
||
## 1.0.2 | ||
|
||
### Patch Changes | ||
|
||
- [#67](https://github.com/mattpocock/ts-error-translator/pull/67) [`dc3d052`](https://github.com/mattpocock/ts-error-translator/commit/dc3d0528b8fa7bd0af38d9f3603d4e836f09e7dd) Thanks [@eddyw](https://github.com/eddyw)! - Add translation for 2761 | ||
|
||
## 1.0.1 | ||
|
||
### Patch Changes | ||
|
||
- [`d458eab`](https://github.com/mattpocock/ts-error-translator/commit/d458eabd0bd2481867eb69661163de2505411133) Thanks [@mattpocock](https://github.com/mattpocock)! - Tweak to 7006 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@total-typescript/error-hint-engine", | ||
"version": "1.0.3", | ||
"license": "MIT", | ||
"main": "./src/index.ts", | ||
"types": "./src/index.ts", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vitest", | ||
"test": "vitest run" | ||
}, | ||
"dependencies": { | ||
"front-matter": "^4.0.2" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.5.3", | ||
"vitest": "^0.10.0", | ||
"esbuild": "^0.14.38", | ||
"tsconfig": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { findHintsInError } from '../errorHintEngine'; | ||
|
||
it('REPL', () => { | ||
const errors = findHintsInError( | ||
`Type 'string' is not assignable to type 'number'.`, | ||
); | ||
expect(errors).toMatchInlineSnapshot(` | ||
[ | ||
"[Not Assignable To](https://totaltypescript.com/concepts/assignability): I expected one thing, but you passed another.", | ||
] | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
export type HintInstruction = | ||
| { | ||
type: 'includes'; | ||
includes: string; | ||
hint: string; | ||
} | ||
| { | ||
type: 'regex'; | ||
regex: RegExp; | ||
hint: string; | ||
}; | ||
|
||
export type TransformedHintInstruction = { | ||
type: 'regex'; | ||
regex: RegExp; | ||
hint: string; | ||
}; | ||
|
||
const hintNamespace = (() => { | ||
const hintInstructions: HintInstruction[] = [ | ||
{ | ||
type: 'includes', | ||
includes: ' not assignable to ', | ||
hint: `[Not Assignable To](https://totaltypescript.com/concepts/assignability): I expected one thing, but you passed another.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: 'parameter', | ||
hint: `[Parameters](https://totaltypescript.com/concepts/parameters) are the names you give to the variables that a function takes.`, | ||
}, | ||
{ | ||
type: 'regex', | ||
regex: /(?<!type )argument/gi, | ||
hint: `[Arguments](https://totaltypescript.com/concepts/arguments) are the values you pass to a function when you call it.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: 'Type argument', | ||
hint: `[Type Arguments](https://totaltypescript.com/concepts/type-arguments) are the types you pass to a generic type, function or class.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: ' used before its ', | ||
hint: `[Used Before Its](https://totaltypescript.com/concepts/used-before-declared): You tried to use something before you declared it.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: ` implicitly has an 'any' type`, | ||
hint: `[Implicit Any](https://totaltypescript.com/concepts/implicit-any): I couldn't figure out what type something is, so I defaulted it to \`any\`.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: `Unused '@ts-expect-error' directive`, | ||
hint: `You used a \`@ts-expect-error\`, but I didn't find any errors on the following line.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: 'Cannot assign to', | ||
hint: `You're trying to modify something that can't be modified.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: ' comparable to ', | ||
hint: `You'll usually see this error when you're trying to use 'as' to cast between two types that aren't compatible.`, | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: `'React' refers to a UMD global`, | ||
hint: 'You either need to import React, or fix the `jsx` property of your `tsconfig.json`. [Full guide](https://www.totaltypescript.com/react-refers-to-a-umd-global).', | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: `JSX.IntrinsicElements`, | ||
hint: '[JSX.IntrinsicElements](https://www.totaltypescript.com/what-is-jsx-intrinsicelements) is a type that describes the valid HTML elements you can use in JSX.', | ||
}, | ||
{ | ||
type: 'includes', | ||
includes: `does not exist on type 'JSX.IntrinsicElements'`, | ||
hint: `You're trying to use an HTML element that doesn't exist on React's types.`, | ||
}, | ||
]; | ||
|
||
const transformedHintInstructions: TransformedHintInstruction[] = | ||
hintInstructions.map((instruction) => { | ||
if (instruction.type === 'includes') { | ||
return { | ||
hint: instruction.hint, | ||
type: 'regex', | ||
regex: new RegExp(instruction.includes, 'ig'), | ||
}; | ||
} | ||
return instruction; | ||
}); | ||
|
||
return { | ||
transformedHintInstructions, | ||
}; | ||
})(); | ||
|
||
export const findHintsInError = (err: string): string[] => { | ||
const hints: string[] = []; | ||
|
||
hintNamespace.transformedHintInstructions.forEach((instruction) => { | ||
if (instruction.type === 'regex') { | ||
if (instruction.regex.test(err)) { | ||
hints.push(instruction.hint); | ||
} | ||
} | ||
}); | ||
|
||
return hints; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './errorHintEngine'; |
Oops, something went wrong.