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

[Improve code]: 型定義はjsonインポートではなく、モジュール内で行うべきである #88

Open
nkte8 opened this issue Apr 8, 2024 · 0 comments
Labels
invalid This doesn't seem right Reminds Low Priority Issue

Comments

@nkte8
Copy link
Owner

nkte8 commented Apr 8, 2024

Where and how it seems bad?

atproto_apiに始まるfetch APIを実行するコード中で、*.jsonをインポートして型定義を行っているが、jsonインポートでの型定義は厳密ではない場合が多く、また名前も一定に定まらないため可読性にすぐれない

以下のようなコードは修正されるべきである

import getEndpoint, { com_atproto, app_bsky } from "./base"
import mtype from "./models/createRecord.json"
import etype from "./models/error.json"
const apiName = com_atproto.repo.createRecord
const endpoint = getEndpoint(apiName)

export const api = async ({
    repo,
    accessJwt,
    record,
}: {
    repo: string
    accessJwt: string
    record: object
}): Promise<typeof mtype | typeof etype> =>
...

What it shoud become?

jsonインポートに対応する型は、jsonインポートを利用するts内で型を定義するべきである。外部から型を読み込む場合も、モジュールから型をimportするべきである。

ただし #15 によりそもそもatproto_apiが不要になると思われる、優先度は低く設定している。
atproto_api以外の箇所については対応するべきである。

@nkte8 nkte8 added invalid This doesn't seem right Reminds Low Priority Issue labels Apr 8, 2024
@nkte8 nkte8 changed the title [Improve code]: jsonインポートではなく、型定義はモジュール内で行うべきである [Improve code]: 型定義はjsonインポートではなく、モジュール内で行うべきである Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right Reminds Low Priority Issue
Projects
Status: No status
Development

No branches or pull requests

1 participant