-
Notifications
You must be signed in to change notification settings - Fork 576
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
refactor(Upload): convert to TypeScript, impove docs and tests, close #4622 #4841
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是您为 Fusion/Next 提的第一个 pr,感谢您为 Fusion 做出的贡献,我们会尽快进行处理。
6e7820e
to
4abb28c
Compare
重新提交了一版 |
重新打开PR |
saveUploaderRef = ref => { | ||
uploaderRef: ReturnType<InstanceType<typeof Upload>['getInstance']>; | ||
|
||
saveUploaderRef = (ref: InstanceType<typeof Upload>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 ref 还可能是 null
|
||
it('should support change Data/Action/Headers in BeforeUpload', () => { | ||
class App extends React.Component { | ||
constructor(props: object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
object 在 ts 里并不是代表 js 里的 Object,这里其实可以把 state 从 constructor 里拿出去,然后 constructor 删掉,类似 demo
assert(fileToObject(file).uid === file.uid); | ||
}); | ||
|
||
it('getFileItem', () => { | ||
const file = { uid: 1, 1: 1 }; | ||
const files = [file, { uid: 2, 2: 2 }]; | ||
const file = { uid: 1, 1: 1 } as unknown as OriginalFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里还是有很多 as unknown,理论上 as known 应该都不存在
components/upload/card.tsx
Outdated
@@ -161,23 +135,24 @@ class Card extends Base { | |||
showDownload, | |||
} = this.props; | |||
|
|||
// @ts-expect-error limit可能为undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里用判空就可以了。
@@ -194,7 +169,7 @@ class Card extends Base { | |||
listType="card" | |||
closable | |||
locale={locale} | |||
value={this.state.value} | |||
value={this.state.value as UploadFile[]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state.value 本身不就是 UploadFile[] 吗,这里为什么还需要 as
|
||
componentDidMount() { | ||
const { props } = this; | ||
const options = this.getUploadOptions(props); | ||
this.uploader = new Uploader(options); | ||
this.uploader = new Uploader(options as unknown as UploadOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要出现 as unknown
@@ -89,7 +56,7 @@ export default class Html5Uploader extends Component { | |||
for (let i = 0; i < keys.length; i++) { | |||
const key = keys[i]; | |||
if (options[key] !== preOptions[key]) { | |||
this.uploader.setOptions(options); | |||
this.uploader.setOptions(options as unknown as UploadOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
} else { | ||
formData.append(option.filename, option.file); | ||
formData.append(option.filename!, option.file as unknown as Blob); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
xhr.onerror = function error(e) { | ||
option.onError(e); | ||
xhr.onerror = function error(e: ProgressEvent<EventTarget>) { | ||
option.onError!(e as unknown as UploadError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
components/upload/util.ts
Outdated
const reader = new FileReader(); | ||
reader.onloadend = () => callback(reader.result); | ||
reader.readAsDataURL(file); | ||
reader.readAsDataURL(file as unknown as Blob); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
提交了一个commit,修复了上面的问题 |
close #4622