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

feat: 拓展ts类型提示 #283

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat: 拓展ts类型提示 #283

wants to merge 2 commits into from

Conversation

AntzyMo
Copy link

@AntzyMo AntzyMo commented Jul 26, 2022

request,get,post的单一any泛型去掉,拓展了更友好的ts提示,可以定义请求data的类型和返回类型

type wxLoginRes = 'code' | 'encryptedData' | 'iv' | 'rawData' | 'signature'
type loginToken = Record<'encryptedData' | 'expirationTimeSeconds' | 'signature', string>
interface loginRes {
  loginToken: loginToken
}

fly.post<Record<wxLoginRes, string>, loginRes>('xxx', {
  code,
  encryptedData,
  iv,
  signature,
  rawData
}).then(res=>{
  res.data.loginToken
})

还可以解构response,只需加上你想要解构的字段就可以,主要用到了UntieResponse类型

fly.post<Record<wxLoginRes, string>, loginRes>('xxx', {
  code,
  encryptedData,
  iv,
  signature,
  rawData
},'data').then(res=>{
  res.loginToken
})

我觉得这样会更好

@AntzyMo
Copy link
Author

AntzyMo commented Jul 31, 2022

请问还在维护吗

@AntzyMo
Copy link
Author

AntzyMo commented Sep 10, 2023

如果可以的话能放点权限让我去维护这库吗?

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

1 participant