quick-lint-js
quick-lint-js copied to clipboard
Parse TypeScript syntax
- [x] interfaces
- [x] classes
- [x] type annotations on variable declarations
- [ ]
<type>variable
type assertions - [ ] abstract methods
- [x]
as
type assertions - [x]
!
postfix operator - [x] type expression syntax
- [x] generic parameters
- [x] generic arguments
- [ ] decorators
- [x] enums
- [x]
import type
- [x]
export interface
,export type
, etc. - [x] namespaces
- [ ]
declare
- [x] type aliases
- [ ]
this
parameters - [ ] type predicates
- [ ]
satisfies
(TS 4.9) - [ ] predeclared global types (e.g.
Generator
)
TypeScript keywords: https://github.com/microsoft/TypeScript/blob/99ffa394a838a5528d6118fb3c23f81fd8e99ab2/src/compiler/scanner.ts#L81
Interfaces
-
interface
s are typechecking-only and cannot be used in expressions. -
function
s,const
/let
/var
/catch
variables, and parameters are runtime-only and cannot be used in types. -
class
es are usable both in expressions and in types. -
import
ed variables are usable according to the above rules. Without looking at the imported module, there is no way to know if an imported variable can be used in an expression or in a type.
Conflicts:
- If an interface and a function/variable have the same name, there is no ambiguity.
- If an interface has the same name as an imported
class
orinterface
, there is a compile error. - If an interface has the same name as an imported
function
/const
/let
/var
, there is no compile error. - If an interface and a class have the same name, then the declarations seem to be merged (union of all members). This can lead to violations in the type system. For example:
interface I { field: number }
class I { }
let o = new I(); // not a type error
console.log(o.field.toString()); // run-time error!
Some interesting syntax quirks related to JSX: https://github.com/rome/tools/blob/f68757316355bb931c0420a686082297978a370e/crates/rome_js_parser/test_data/inline/err/jsx_or_type_assertion.js https://stackoverflow.com/a/54614279/39992
Here's an interesting file we could use for performance testing (almost 7 MiB): https://raw.githubusercontent.com/NativeScript/NativeScript/main/packages/types-android/src/lib/android/android-platform-31.d.ts
and another (over 2 MiB): https://github.com/microsoft/TypeScript/blob/main/src/compiler/checker.ts
TypeScript has too many syntax-level features. @_@
TypeScript has too many syntax-level features. @_@
you're tellin' me!
Shipped in version 3.0.0.