Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design Meeting Notes, 2/18/2022 #48017

Closed
DanielRosenwasser opened this issue Feb 23, 2022 · 0 comments
Closed

Design Meeting Notes, 2/18/2022 #48017

DanielRosenwasser opened this issue Feb 23, 2022 · 0 comments
Labels
Design Notes Notes from our design meetings

Comments

@DanielRosenwasser
Copy link
Member

Contextually Typed and Satisfies Operator

#47920
https://github.com/microsoft/TypeScript/pull/47898/files

  • Looked through use-cases.
    • Safe type assertion
    • Property name constraints
      • "these properties may exist"
    • Property name fulfillment
      • "these properties must be present"
    • Property value conformance
      • "these properties must have the right types"
    • Ensure interface implementation
      • "I don't care about excess properties, but this has to satisfy this interface"
    • Optional Member Conformance
      • "The values conform to this type, but I want to hold on to the original type"
    • ...
    • More - check the issue
  • Excess property checks?
    • Seems like you can just issue them by default and a user can intersect with Record<string, unknown> to opt out.
      • someExpression satisfies SomeType & Record<string, unknown>
    • Could go the other way to achieve excess property checks by intersecting with Record<string, never>
      • But excess property checks are part of the assignability relationship anyway. We don't want a second check.
  • Aside, maybe safe upcast could be achieved with x satisfies T as T
  • Empty arrays!
  • Syntax side?
    • satisfies?
    • extends? We use that for type parameters that must be assignable to a constraint.
    • implements is what we use for classes - also closer in intuition
      • But also both of
    • Reuse as syntax like as const?
      • Would be nice because we could reuse JSDoc cast syntax.
    • is? Could conflict with pattern matching.
    • Marker type?
      • expr as Satisfies<T>
  • Are we satisfied?
    • 🙄

Definite Assignment Checks for Computed Keys

#45974

  • Seems like this is broader than the issue described.
    • Yes, we will now narrow any element access reference.

      const sym = Symbol();
      
      declare let x: {
          [sym]: number | string;
      };
      
      if (typeof x[sym] === "number") {
          let a = x[sym]; // 'number | string' today, 'number' with this PR
      }
  • We like this, but this is more work for every program, not just restricted to classes.
  • It's a relatively small slowdown, but every slowdown adds up over a few releases.
  • Want to get more eyes on this so we feel comfortable with the change.
@DanielRosenwasser DanielRosenwasser added the Design Notes Notes from our design meetings label Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Notes Notes from our design meetings
Projects
None yet
Development

No branches or pull requests

1 participant