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

seq()の型定義 #8

Merged

Conversation

ThinaticSystem
Copy link
Contributor

@ThinaticSystem ThinaticSystem commented Aug 5, 2022

Description

#7 の実装

TODO

  • 型定義
    • selectorなしのときの返り値
      ユニオンの型変数として受け取りたいがなんもわからんのです!
      -> https://misskey.io/notes/93kppsqs6d
    • selectorありのときの返り値
      引数の型宣言を[...T]みたいに書くとタプル型をいい感じに受け取れるっぽく、できた
    • 3つ目のやつの返り値
      1つ目のやつができればいけそう

Issue ID

#7

@ThinaticSystem
Copy link
Contributor Author

image
return success(latestIndex, (select != null ? accum[select] : accum));してるとこで型の整合怒られてる
使う分には動いてそう
なんか惜しい…

@ThinaticSystem
Copy link
Contributor Author

三項演算子使うのやめたら型エラー消えた
TSのバグ説ある(ほんまか)

@marihachi
Copy link
Member

三項演算子の型ガードがそもそもサポートされてるのかが怪しくなってる

@ThinaticSystem
Copy link
Contributor Author

まりはちが投げてたやつに書き換えた上で
一応selectへ明示的にundefinedが突っ込まれたときにParser[]で返す(selectを指定しなかった場合の返り値)ようにした
その場合の型は諦めてUnknownで返るようになってる
(オプション引数へ明示的に突っ込まれたundefinedの判定がJavaScriptの(typeof opt === 'number')とかでしかできないっぽく、TypeScript空間で型を分岐させるのはちょっとむつかしそうだった)

@ThinaticSystem ThinaticSystem marked this pull request as ready for review August 6, 2022 11:16
@ThinaticSystem
Copy link
Contributor Author

一応selectへ明示的にundefinedが突っ込まれたときにParser[]で返す(selectを指定しなかった場合の返り値)ようにした

これ要ると思う?

src/index.ts Outdated Show resolved Hide resolved
@marihachi
Copy link
Member

一応selectへ明示的にundefinedが突っ込まれたときにParser[]で返す(selectを指定しなかった場合の返り値)ようにした

これ要ると思う?

これ要らないかも
明示的に指定することがなさそう

Copy link
Member

@marihachi marihachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

src/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@marihachi marihachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

その他は良さそう

Copy link
Member

@marihachi marihachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

完璧:rocket:

@marihachi marihachi merged commit 4f286e6 into terrario-js:develop Aug 6, 2022
@marihachi
Copy link
Member

ありがとう! 🙏 🙏 🙏 🙏

@hogemori
Copy link

hogemori commented Aug 6, 2022

三項演算子使うのやめたら型エラー消えた TSのバグ説ある(ほんまか)

typeof selectのまわりの括弧をとるとエラーでないかもしれないです。例:
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMAFADwPwC5FhAWwCMBTAJwEoBvAKETsQHoHEBhOfABwENSYBnBIgCMWWvSaIICAQBtiAOhlwA5ihRQAnh2JxgiNOUQBeE4gDkeImTOIMiALRpEOAEQA5OFERdcBEqXkXcgBuOgkAFS1iRDJSOACxOikwWQUlVU1tXX1jI0QXS38XWwcnVw8vH0KyQJCw5gB5AGlqRMZmNk4efkEAJlF6dslpL0ydYCc8sey0YLaJZNTFFXUo3UnTCz9rEsdnfIrvXysAoNChyO0Y0jiEwcWvZIATY0RVrL0DXLytk7M5+7SOByZaqZ67MoHTxHaqnOpDZqtQYSABCGkQUAAFtEAO5cDTyQnzZjhTFwPjRDhxQhyfB8bykaJgaF8bQQGDAGAQDFwDHYjFkMA8dFwbSkLhQeKIQggSoyATeDgcGToyWIAAGHPViD4UAlxHwxDAUD4A3EzA5b3e430hhMP1hZkMi2BaRWjnhESi11u8jalutM2+5kdzqBIPSKA95wkiIAvq1UAAGcjUVCpoA

typeof select === honiの形式で書かないと型の絞り込みをしてるんだなって思ってくれないんじゃないでしょうか。(たぶん有効なパターンが限られている)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants