Skip to content

Design Meeting Notes, 6/15/2022 #49579

Closed
Closed
@DanielRosenwasser

Description

@DanielRosenwasser

More-Specific TemplateStringsArray

#49552

  • We have a sort of gap in what you can express between function calls and tagged templates.
  • Some things that are lacking
    • Being able to infer specific values and raw values in place of a more-broad TemplateStringsArray type.
    • Inference in the face of intersections.
  • Why? Why now?
    • Has come up in a few issues.
    • Relatively little work.
    • Wanted to power more powerful mechanisms using plug-ins in tsc, but the type-system might be powerful enough now.
    • It's an asymmetry with function calls.
  • We said don't do this (Design Meeting Notes, 8/18/2021 #45504). The type system isn't optimized to be a parser. Function calls maybe provide enough "syntactic salt". So why do we want to incentivize this?
    • You can already do this today.
    • Also, language service plugins can give you errors, but you can't get a better type.
  • Tuple inferences may be good regardless of this change.
  • Can give more specific return types, can validate the string, and even use inference to validate the string.
    • Should make sure the DSL libraries we're trying to model here are actually tested.
    • But also, the error messages that these produce will be totally unappetizing.
  • Conclusion
    • Not 100% sold across the team, but we can convince ourself that it's reasonable to bring in. Not a priority for TS 4.8, but if it gets in, it gets in.

A Tour of Module Resolution Strategies

https://gist.github.com/andrewbranch/3020c4e24092bd37f7e210d6f050ef26

  • Node.js 16+ ESM support was a good focus, but lots of other resolvers that have a non-consistent set of features.
  • Been telling people "you need to reference .js as a module extension" for Node.js.
    • If that's too painful, but maybe you shouldn't use the new mode if you're not using Node - but then what should people be doing?
    • Usually the best, most-maximal one is just called, uh, node.
  • People using bundlers are often best-off targeting --moduleResolution node.
    • But then every bundler supports the exports field.
    • But then our old node mode doesn't understand that.
      • Maybe we should pick that into node?
        • Seems like a "duh!" but then...why don't we see lots of demand for this!?
          • Hypotheses:
            • Relatively uncommon to use exports.
            • ESM/CJS APIs are similar enough.
            • People don't know how to ask, especially because this is so confusing.
  • This is all very confusing - if people are so frustrated, couldn't we transform paths based on .ts to .js?
    • Always comes up - but it amounts to a transformation from a "TypeScript-specific module system" to several target module systems, and they need to be able to compose well.
      • How do you deal with lies in .d.ts resolution?
      • Do the .ts extensions get preserved in .d.ts files?
      • How does it deal with dynamic imports? Do you need a TS dynamic import helper for non-static imports?
      • How do you refer to dependencies in packages which are exposed as .js files? They aren't .ts files.
  • The point of this table is not to try to model every single bundler behavior, it's to try to figure out the common module targets and where we have a gap.
  • So one of those common targets is places where you don't need a compiler and the runtime/resolver can do the TS -> JS transform (e.g. Deno, bundlers, etc.).
  • No conclusion, but at least feel like we're getting a better understanding of the lay of the land.

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