quick-lint-js icon indicating copy to clipboard operation
quick-lint-js copied to clipboard

Parse TypeScript syntax

Open strager opened this issue 2 years ago • 4 comments

  • [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)

strager avatar Apr 15 '22 08:04 strager

TypeScript keywords: https://github.com/microsoft/TypeScript/blob/99ffa394a838a5528d6118fb3c23f81fd8e99ab2/src/compiler/scanner.ts#L81

strager avatar Apr 30 '22 04:04 strager

Interfaces

  • interfaces are typechecking-only and cannot be used in expressions.
  • functions, const/let/var/catch variables, and parameters are runtime-only and cannot be used in types.
  • classes are usable both in expressions and in types.
  • imported 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 or interface, 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!

strager avatar May 01 '22 03:05 strager

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

strager avatar May 27 '22 08:05 strager

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

strager avatar Jul 29 '22 07:07 strager

TypeScript has too many syntax-level features. @_@

strager avatar Sep 29 '22 07:09 strager

TypeScript has too many syntax-level features. @_@

you're tellin' me!

vegerot avatar Jan 26 '23 23:01 vegerot

Shipped in version 3.0.0.

strager avatar Jan 01 '24 22:01 strager