Incorrect/misleading example use-case for `ifDefined` directive

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
52/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
documentation

調査の方向性

リンク先のLitドキュメントにあるifDefinedディレクティブのセクションから始め、引用されているガイダンスと画像の例を確認してください。不完全なimg srcを推奨される実践として示さないように、例または説明を更新してください。文書化されたユースケースが正確で明確になれば、このセクションは完了です。

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

説明

Hi! In the docs for the ifDefined directive, we read the following:

This is especially useful for setting URL attributes, when the attribute should not be set if required parts of the URL are not defined, to prevent 404's.

and there's the following code example:

@customElement('my-element')
class MyElement extends LitElement {

  @property()
  filename: string | undefined = undefined;

  @property()
  size: string | undefined = undefined;

  render() {
    // src attribute not rendered if either size or filename are undefined
    return html`<img src="/images/${ifDefined(this.size)}/${ifDefined(this.filename)}">`;
  }
}

The example clearly shows how it works, however the src is a mandatory attribute of the img element, and in such a case, I think the better way of doing things would be to not render the img at all.

Please don't get me wrong – I'm of course aware that this is just an example, but if such a code snippet is presented in a documentation of a library, it could be considered by many people as a good/common practice.

I wasn't able to find out a good alternative to that in a reasonable timespan, so I'm just leaving this issue as a note or a small issue report.

主要言語
TypeScript
スター
140
フォーク
229
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

lit/lit.dev のほかの issue

lit/lit.dev の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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