I am facing an issue with my TypeScript method that includes a type guard:
export function isArray(item: any): item is Array<any> {
return item.constructor === Array;
}
After running tslint
on the file, I encountered the following error message:
1:42 error Parsing error: Unexpected token, expected "{"
> 1 | export function isArray(item: any): item is Array<any> {
| ^
2 | return item.constructor === Array
3 | }
The linter seems to parse the type guard as a syntactic error. This problem occurs consistently across all my type guards.
Can anyone provide insights into what might be causing this issue? I couldn't find any similar cases online.
Appendix
The versions of TypeScript and tslint I am using are:
"tslib": "1.9.3",
"tslint": "5.13.1",
"tslint-config-prettier": "1.18.0",
"tslint-eslint-rules": "5.4.0",
"tslint-react": "3.6.0",
"typescript": "3.3.3333",
My configuration for tslint
is as follows:
{
"extends": [
"tslint:latest",
"tslint-react",
"tslint-eslint-rules",
"tslint-config-prettier"
],
"rules": {
"no-submodule-imports": [true, "react-native-vector-icons"],
"interface-name": [true, "always-prefix"],
"object-literal-sort-keys": [false],
"semicolon": [true, "never"],
"jsdoc-format": [false],
"valid-jsdoc": [false],
"no-unnecessary-type-assertion": [true],
"max-classes-per-file": [false, 2],
},
"linterOptions": {
"exclude": [
"node_modules",
"app/**/**.js",
"packager/**"
]
}
}