microsoft / microsoft/TypeScript

`Error.stack` type definition in lib.es5.d.ts is incorrect / `exactOptionalPropertyTypes` incompatible

オープン
#45,748 コメント 7 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Domain: lib.d.ts
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Bug Report

🔎 Search Terms

Error.stack, exactOptionalPropertyTypes, ErrnoException

🕗 Version & Regression Information
  • This is a type issue
  • This changed in #8705 but it took until the 4.4 release for it to surface, thanks to exactOptionalPropertyTypes and it making Error incompatible with a corrected Error-subclass in @types/node: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55425
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about es5
⏯ Playground Link

Playground link with relevant code which is valid according to the ECMAScript spec and basically every other JS spec out there as .stack isn't standardized (as far as eg. MDN knows at least)

Edit: @ljharb has an ECMAScript Stage 1 proposal for an Error Stacks spec.

💻 Code
interface MyCoolStack {
    line: string
}

interface MyError extends Error {
    stack: MyCoolStack
}
🙁 Actual behavior

Got error:

Interface 'MyError' incorrectly extends interface 'Error'.
  Types of property 'stack' are incompatible.
    Type 'MyCoolStack | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.
🙂 Expected behavior

One of two:

  1. Either that it passes completely...
  2. ...or at least that it complains the same as it does with exactOptionalPropertyTypes turned off:
Interface 'MyError' incorrectly extends interface 'Error'.
  Types of property 'stack' are incompatible.
    Type 'MyCoolStack | undefined' is not assignable to type 'string | undefined'.
      Type 'MyCoolStack' is not assignable to type 'string'.

Edit: The ECMAScript Stage 1 proposal for an Error Stacks spec defines that the stack should be of type string|undefined, which makes the current type of stack?:string wrong and should be replaced with stack?:string|undefined if one agrees with that specs view of the current state of Error stacks.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

lib.es5.d.ts の Error 宣言を調査し、リンク先の TypeScript Playground で exactOptionalPropertyTypes を有効にした場合と無効にした場合の両方について、報告された非互換性を再現してください。得られた診断を期待される動作およびリンク先の Error Stacks proposal と比較してください。宣言が Error.stack に対してプロジェクトが選択したセマンティクスを反映していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。