Skip to content

Design Meeting Notes, 10/4/2023 #55993

@DanielRosenwasser

Description

@DanielRosenwasser

Unique Symbols, Widening, and Declaration Emit

#55901
#55943

export const l = "A";
export const l1 = l as typeof l;
export const l2 = l;
export let l3 = l as typeof l;
export let a4 = l;

export const s = Symbol();
export const s1 = s as typeof s;
export const s2 = s;
export let s3 = s as typeof s;
export let s4 = s;
  • Two kinds of symbols, widened and non-widened.
  • For declaration emit, s1 should say typeof s.
  • Could imagine an alternative world where unique symbol is the default - we don't widen those away. You say : symbol if you want to handle arbitrary symbols.
    • What about widening return values from functions?
  • We don't widen fresh literals all the time - conditional types don't work the same.
  • Other view: unique symbols widen just like all other literal types.
  • Let's try https://github.com/microsoft/TypeScript/pulls/55943 in 5.4 with literal widening unification.

Uninitialized Variable Checks

#23305

  • We don't do control flow analysis across functions, so we can't catch "you never initialized this" checks across function boundaries.
  • error on variables that are used but never initialized #55887 is a PR to say "if a variable was never ever set but it's used somewhere, it's an error"
  • There's some cases where "I'm temporarily erasing some code and I don't want an error"
    • Well add a ! or say the variable is possibly undefined.
  • We need to have tests for a ! as both a non-null assertion and an initialized variable assertion.
  • Would be better to do this on the use-site.
  • Also a better error message would be "is never initialized".
  • Should just let x: string with no usages at all be an error?
    • Hate this because "I'm not done typing", but can be caught by unused variable checks/linters.

Stage Advancement Planning

  • At TC39, there was a proposal that ECMA262/TC39 should change the staging process to add a new stage between Stages 2 and 3.
  • Results at plenary:
    • Consensus: there should be a new stage
    • No consensus: name of the stage (2 ¾, 3.a/3.b, add a new stage and shift 3 and 4 over to 4 and 5...)
      • Mostly devolved into jokes.
      • We would just prefer to insert a new thing and shift 3/4 over to 4/5.
  • Issue is that proposals need to have tests before implementers start implementing.
    • Polyfills, possibly eager compilers will implement at the new pre-today's-stage-3 stage
    • Everything else will implement after tests are written.
  • We will probably implement/ship post-tests, not pre-tests.
    • We rarely do the "ship it behind a flag".
    • We can implement early for feedback as implementers/users, but we won't ship early.

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