Skip to content

Design Meeting Notes, 2/24/2023 #52953

@DanielRosenwasser

Description

@DanielRosenwasser

Libraries Patching TypeScript's API

https://gist.github.com/jakebailey/3e73c7aab4da2044a95121467aa3b4e9

  • In TypeScript 5.0, libraries can no longer override properties of our API.
  • Language service plugins
    • typescript-plugin-css-modules
      • Can no longer patch createLanguageServiceSourceFile and updateLanguageServiceSourceFile
      • Make ones up with CSS.
      • Should be proxying the language service host
    • vuejs/language-tools
      • Same deal with resolveModuleName
        • The new 5.0 resolution modes are better fits.
          • --moduleResolution bundler
          • --allowArbitraryExtensions
            • Use .d.vue.ts files.
      • There's really no host-level function they can override? Surprising.
        • Seems like no?
        • But resolveModuleName takes a ModuleResolutionHost - is there a way to control that?
          • Seems fairly file-system-oriented.
        • Actually some hosts do have a resolveModuleNames
          • proxyPluginHost should set host.resolveModuleNameLiterals.
      • Still, using the new resolution modes is recommended, but if they're determined to support node16/nodenext (they shouldn't, we don't believe it's actually the the right thing to use), patching resolveModuleNameLiterals is the right thing.
      • Meta: they recommend most users use this instead of our language server: https://vuejs.org/guide/typescript/overview.html#volar-takeover-mode
  • Supporting Transformers
    • ttypescript
      • createProgram
    • ts-patch
      • createProgram, lots of other top-level stuff to enable caching.
    • The core idea is that these packages don't want to support all of the tsc command line and whatnot.
    • Is executeCommandLine public?
      • Yes. (later: no)
      • Then they should be using that.
      • Ehh, it's not exported.
        • Only internally exported for testing scenarios.
      • Also there's no emit hook. Can't plug transforms in today.
      • program.emit is overridable from executeCommandLine
        • But that happens after emit occurs.
        • But you can set noEmit and then force emit.
        • But then you don't get declaration file diagnostics.
    • Come back to these.
  • Stencil - has its own compiler
    • Sets ts.sys
    • We have an /* @internal */ function setSys that they can use.
    • Also use resolveModuleName - they should be passing this into the CompilerHost they create
    • So actually, most of this should be on the CompilerHost
    • There are some functions they patch which we missed.
  • Heft
    • Build system that wraps TypeScript.
    • readJson - only reason for this is caching.
    • emitFiles - patched so that they can support multiple emit targets.
    • Possible idea: you have the CompilerHost, just patch it every time and re-run emit.
      • Tried, but was unsuccessful.
  • Yarn
    • Still works! Patched in a different way, maintained in a fork.
    • Would like to make this easier, but not in near-term range.

Comparing Wrapper Objects

  • 1 is a number
  • Number(1) is a number
  • new Number(1) is a Number - a wrapper object.
  • All numeric and relational operations turn the wrapper objects back into their primitive equivalents.
  • === is suspect though.
  • In 5.0, number < Number is disallowed
  • We have a change that makes relational comparison consider valueOf (Stricter relational comparisons checking valueOf #52807) - which re-allows number < Number!
  • We don't feel like it's a huge problem to error on these - would prefer people not use these types.
  • People shouldn't be referencing these anyway - default typescript-eslint rule is ban-types which stops these.
    • So not unbreaking number < Number in 5.0 - it's too late in the game regardless of what happens in 5.1.
  • Aside: probably should not perform these in the relationship checks, should liken these to the NaN checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design NotesNotes from our design meetings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions