Skip to content

Design Meeting Notes, 1/22/2021 #42589

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

Closed
DanielRosenwasser opened this issue Feb 1, 2021 · 4 comments
Closed

Design Meeting Notes, 1/22/2021 #42589

DanielRosenwasser opened this issue Feb 1, 2021 · 4 comments
Labels
Design Notes Notes from our design meetings

Comments

@DanielRosenwasser
Copy link
Member

Template String Types for Template Expressions

(continued)

  • Strong feelings on this?

    • Seems better, and more consistent, with templates with no holes.
    • As soon as you added holes in positions, then you lose it.
    • So part of the idea is we're trying to faithfully reflect what's happening in the type system.
  • + concatenations don't do this though - that's very inconsistent.

  • If we were to introduce + for any T and U.

  • We don't support algebraic operators in general.

    const a: 42 = 42;
    const b: 3  = 3;
    const c = a + b
  • In DefinitelyTyped, we recently had a PR with a huge number of strings - one could argue that's strictly better.

  • Should a new programmer have to see this behavior?

  • New programmer will usually see a union type.

    • Will sometimes see a template with an interpolated string though!
  • There's a widening/non-widening form, right?

  • Consistency arguments don't exactly feel useful because you want the literal type so you can compare for literal unions.

    • When you have an infinite set...that feels somewhat less useful.
    • Consistency vs. usability argument, usability feels more compelling to me.
  • Could imagine "only create a literal type if it's finite"

    • Still hard to explain "if you fill your hole with a string, you won't get a literal-ish type."
  • Maybe the most minimal change is to make return statements do different widening.

  • Can always opt in with as const with old behavior.

  • There is some sentiment that the behavior is good; but should just make concessions to widening on function returns.

    // This should probably keep working like it does post-PR:
    let a = 12;
    const lit = `${a}px`;
    usePxValue(lit);
    const obj = {
        lit
    };
  • But feels strange, that if you wrote this as makePx, and we widened for you, that'd be bad.

  • unique symbols widen to symbols.

  • Seems like these should work the same.

    let a = 12;
    const c = `${x}px`;
    
    function makePxValue1(x: number) {
        return `${x}px`;
    }
    
    function makePxValue2(x: number) {
        const c = `${x}px`;
        return c;
    }
  • If we revert, we can avoid all these contextual rules.

    • Only time we infer literal types is if they're finite.
    • Also, can maintain the string slots when contextually typed.
  • Seems like reverting is a reasonable option, so you'd just end up with string unless you write as const - same way with arrays/object literals.

  • What kind of inferences would we need to make this better? Seems like these are desirable.

    • Well you have to speculate with these super-specific types - that's why we have widening. So you don't really know.
    • We need to see where/when/how types are mutated.
@awerlogus
Copy link

It would be nice if everything will work without features that are specific for .ts files and are not currently supported by checkjs, like as const, for example.

@AlCalzone
Copy link
Contributor

I'd really like a way to opt in with JS which seems impossible since JS has no "as const".

@jcalz
Copy link
Contributor

jcalz commented Feb 8, 2021

@DanielRosenwasser 1/22/2020 was more than a year ago; how did you remember all these meeting notes? 😜

@RyanCavanaugh RyanCavanaugh changed the title Design Meeting Notes, 1/22/2020 Design Meeting Notes, 1/22/2021 Feb 8, 2021
@pedrodurek
Copy link

pedrodurek commented Feb 12, 2021

It'd be nice having the Template Literal Inference back. I was really expecting this feature, I even mentioned it on our doc 😢 . In my view, as long as the expression from the template string is a literal value, we should appropriately infer that template string (return the merged literal value rather than just string). I hope you consider bringing it back 🙏.

bors bot referenced this issue in jser/jser.github.io Feb 16, 2021
837: 2021-02-16のJS: TypeScript 4.2 RC、WebdriverIO v7、Nuxt.js 2.15.0 r=azu a=azu

TypeScript 4.2 RCがリリースされています。

- [Announcing TypeScript 4.2 RC | TypeScript](https://devblogs.microsoft.com/typescript/announcing-typescript-4-2-rc/)

Tuple TypesでRest Elementをサポート、Type Aliasの型追跡の仕組みを改善して表示される型が分かりやすくなるように。
また、オブジェクトではないオペランドに対して`in`演算子を利用した場合に、コンパイルエラーとなるように変更。
その他には、`noPropertyAccessFromIndexSignature`オプションの追加、`abstract new`のサポート、`--explainFiles`フラグが追加されています。

[TypeScript 4.2 Beta](https://devblogs.microsoft.com/typescript/announcing-typescript-4-2-beta/)の時点では、Template Literal式をデフォルトでTemplate Literal Typeとして扱うように変更されていました。
しかし、この挙動は[望ましくないケース](https://github.com/microsoft/TypeScript/issues/42589)もあることがわかり、revertしてデフォルトでは`string`として扱うようになっています。
4.2 RCでは、Template Literal式に `as const` をつけた場合のみ、Template Literal Typeとして扱うようになっています。

```ts
declare const yourName: string;

// 'bar' has type '`hello ${string}`'.
const bar = `hello ${yourName}` as const;
//                              ^^^^^^^^

// 'baz' has type 'string'.
const baz = `hello ${yourName}`;
```

---

WebdriverIO v7がリリースされました。

- [WebdriverIO v7 Released | WebdriverIO](https://webdriver.io/blog/2021/02/09/webdriverio-v7-released/)


Node.js 10のサポート終了、TypeScriptでの書き直し、Cucumber v7へアップデート、Lightouse連携の改善が含まれています。
`browser.checkPWA()`の追加、`@babel/register`や`ts-node`がインストールされている場合に自動的にコンパイルする[`autoCompileOpts`](https://webdriver.io/docs/configurationfile)オプションの追加などが含まれています。

---

Nuxt.js 2.15.0がリリースされています。

- [Release v2.15.0 · nuxt/nuxt.js](https://github.com/nuxt/nuxt.js/releases/tag/v2.15.0)
- [nuxt/components: Scan and auto import components for Nuxt.js 2.13+](https://github.com/nuxt/components#migration-guide)
- [nuxt-contrib/jiti: Runtime Typescript and ESM support for Node.js](https://github.com/nuxt-contrib/jiti)

破壊的な変更としてNode.js 10のサポート終了、`@nuxt/components` v2へのアップデートが含まれています。
`@nuxt/components` v2へのアップデートするマイグレーションガイドも公開されています。

- [nuxt/components: Scan and auto import components for Nuxt.js 2.13+](https://github.com/nuxt/components#migration-guide "nuxt/components: Scan and auto import components for Nuxt.js 2.13+")

その他にはYarnのPlug'n'Playのサポート、PostCSS 8をopt-inでサポートしています。

Co-authored-by: azu <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: azu <[email protected]>
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

5 participants