Skip to content

Commit

Permalink
TS strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon committed Jun 18, 2024
1 parent 287764f commit 1fb5472
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/audio/src/Audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class Audio<M extends Meta, B extends Body> extends UIPlugin<
> {
static VERSION = packageJson.version

#recordingLengthTimer: ReturnType<typeof setInterval>
#recordingLengthTimer: ReturnType<typeof setInterval> | undefined

private icon

Expand Down
10 changes: 5 additions & 5 deletions packages/@uppy/audio/src/audio-oscilloscope/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export default class AudioOscilloscope {

private bufferLength: number

private dataArray: Uint8Array
private dataArray: Uint8Array | undefined

// eslint-disable-next-line no-use-before-define
private onDrawFrame: (oscilloscope: AudioOscilloscope) => void

private streamSource?: MediaStreamAudioSourceNode

private audioContext: BaseAudioContext
private audioContext: BaseAudioContext | undefined

public source: AudioBufferSourceNode
public source: AudioBufferSourceNode | undefined

constructor(
canvas: HTMLCanvasElement,
Expand Down Expand Up @@ -98,7 +98,7 @@ export default class AudioOscilloscope {
const h = this.height

if (analyser) {
analyser.getByteTimeDomainData(dataArray)
analyser.getByteTimeDomainData(dataArray!)
}

ctx.fillRect(0, 0, w, h)
Expand All @@ -112,7 +112,7 @@ export default class AudioOscilloscope {
}

for (let i = 0; i < bufferLength; i++) {
const v = dataArray[i] / 128.0
const v = dataArray![i] / 128.0
const y = v * (h / 2)

if (i === 0) {
Expand Down
18 changes: 9 additions & 9 deletions packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@ function removeMetadataFromURL(urlString: string) {
}

export class HTTPCommunicationQueue<M extends Meta, B extends Body> {
#abortMultipartUpload: WrapPromiseFunctionType<
#abortMultipartUpload!: WrapPromiseFunctionType<
AwsS3Multipart<M, B>['abortMultipartUpload']
>

#cache = new WeakMap()

#createMultipartUpload: WrapPromiseFunctionType<
#createMultipartUpload!: WrapPromiseFunctionType<
AwsS3Multipart<M, B>['createMultipartUpload']
>

#fetchSignature: WrapPromiseFunctionType<AwsS3Multipart<M, B>['signPart']>
#fetchSignature!: WrapPromiseFunctionType<AwsS3Multipart<M, B>['signPart']>

#getUploadParameters: WrapPromiseFunctionType<
#getUploadParameters!: WrapPromiseFunctionType<
AwsS3Multipart<M, B>['getUploadParameters']
>

#listParts: WrapPromiseFunctionType<AwsS3Multipart<M, B>['listParts']>
#listParts!: WrapPromiseFunctionType<AwsS3Multipart<M, B>['listParts']>

#previousRetryDelay: number
#previousRetryDelay!: number

#requests

#retryDelays: { values: () => Iterator<number> }
#retryDelays!: { values: () => Iterator<number> }

#sendCompletionRequest: WrapPromiseFunctionType<
#sendCompletionRequest!: WrapPromiseFunctionType<
AwsS3Multipart<M, B>['completeMultipartUpload']
>

#setS3MultipartState

#uploadPartBytes: WrapPromiseFunctionType<uploadPartBytes>
#uploadPartBytes!: WrapPromiseFunctionType<uploadPartBytes>

#getFile

Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/aws-s3/src/MultipartUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class MultipartUploader<M extends Meta, B extends Body> {

#abortController = new AbortController()

#chunks: Array<Chunk | null>
#chunks: Array<Chunk | null> = []

#chunkState: { uploaded: number; etag?: string; done?: boolean }[]
#chunkState: { uploaded: number; etag?: string; done?: boolean }[] = []

/**
* The (un-chunked) data to upload.
Expand Down Expand Up @@ -131,7 +131,7 @@ class MultipartUploader<M extends Meta, B extends Body> {
if (shouldUseMultipart && fileSize > this.#minPartSize) {
// At least 5MB per request:
let chunkSize = Math.max(
this.options.getChunkSize(this.#data),
this.options.getChunkSize(this.#data) as number, // Math.max can take undefined but TS does not think so
this.#minPartSize,
)
let arraySize = Math.floor(fileSize / chunkSize)
Expand Down
10 changes: 6 additions & 4 deletions packages/@uppy/aws-s3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ type AWSS3MultipartWithoutCompanionMandatorySignPart<
) => MaybePromise<AwsS3UploadParameters>
}
type AWSS3MultipartWithoutCompanionMandatory<M extends Meta, B extends Body> = {
getChunkSize?: (file: UppyFile<M, B>) => number
getChunkSize?: (file: { size: number }) => number
createMultipartUpload: (file: UppyFile<M, B>) => MaybePromise<UploadResult>
listParts: (
file: UppyFile<M, B>,
Expand Down Expand Up @@ -314,7 +314,7 @@ export default class AwsS3Multipart<

#companionCommunicationQueue

#client: RequestClient<M, B>
#client!: RequestClient<M, B>

protected requests: any

Expand Down Expand Up @@ -530,7 +530,7 @@ export default class AwsS3Multipart<
.then(assertServerError)
}

#cachedTemporaryCredentials: MaybePromise<AwsS3STSResponse>
#cachedTemporaryCredentials: MaybePromise<AwsS3STSResponse> | undefined

async #getTemporarySecurityCredentials(options?: RequestOptions) {
throwIfAborted(options?.signal)
Expand Down Expand Up @@ -859,7 +859,9 @@ export default class AwsS3Multipart<

log: (...args: Parameters<Uppy<M, B>['log']>) => this.uppy.log(...args),
getChunkSize:
this.opts.getChunkSize ? this.opts.getChunkSize.bind(this) : null,
this.opts.getChunkSize ?
this.opts.getChunkSize.bind(this)
: undefined,

onProgress,
onError,
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/drop-target/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class DropTarget<
> {
static VERSION = packageJson.version

private removeDragOverClassTimeout: ReturnType<typeof setTimeout>
private removeDragOverClassTimeout: ReturnType<typeof setTimeout> | undefined

private nodes?: Array<HTMLElement>

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/file-input/src/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class FileInput<M extends Meta, B extends Body> extends UIPlugin<
> {
static VERSION = packageJson.version

input: HTMLFileInputElement | null
input: HTMLFileInputElement | null = null

constructor(uppy: Uppy<M, B>, opts?: FileInputOptions) {
super(uppy, { ...defaultOptions, ...opts })
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/form/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Form<M extends Meta, B extends Body> extends BasePlugin<
> {
static VERSION = packageJson.version

#form: HTMLFormElement
#form!: HTMLFormElement

/**
* Unfortunately Uppy isn't a state machine in which we can guarantee it's
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/golden-retriever/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class GoldenRetriever<

IndexedDBStore: IndexedDBStore

savedPluginData: Record<string, unknown>
savedPluginData: Record<string, unknown> | undefined

constructor(uppy: Uppy<M, B>, opts?: GoldenRetrieverOptions) {
super(uppy, { ...defaultOptions, ...opts })
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/image-editor/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default class Editor<M extends Meta, B extends Body> extends Component<
Props<M, B>,
State
> {
imgElement: HTMLImageElement
imgElement!: HTMLImageElement

cropper: Cropper
cropper!: Cropper

constructor(props: Props<M, B>) {
super(props)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/image-editor/src/ImageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class ImageEditor<
> extends UIPlugin<InternalImageEditorOpts, M, B, PluginState<M, B>> {
static VERSION = packageJson.version

cropper: Cropper
cropper!: Cropper

constructor(uppy: Uppy<M, B>, opts?: Opts) {
super(uppy, {
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/react/src/FileInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class FileInput<M extends Meta, B extends Body> extends Component<
inputName: 'files[]',
}

private container: HTMLElement
private container!: HTMLElement

private plugin: UnknownPlugin<M, B>
private plugin: UnknownPlugin<M, B> | undefined

componentDidMount(): void {
this.installPlugin()
Expand Down Expand Up @@ -65,7 +65,7 @@ class FileInput<M extends Meta, B extends Body> extends Component<
uninstallPlugin(props = this.props): void {
const { uppy } = props

uppy.removePlugin(this.plugin)
uppy.removePlugin(this.plugin!)
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/screen-capture/src/RecorderScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type RecorderScreenProps<M extends Meta, B extends Body> = {
class RecorderScreen<M extends Meta, B extends Body> extends Component<
RecorderScreenProps<M, B>
> {
videoElement: HTMLVideoElement | null
videoElement: HTMLVideoElement | null = null

componentWillUnmount(): void {
const { onStop } = this.props
Expand Down
12 changes: 6 additions & 6 deletions packages/@uppy/screen-capture/src/ScreenCapture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ export default class ScreenCapture<
type: string
}

videoStream: null | MediaStream
videoStream: null | MediaStream = null

audioStream: null | MediaStream
audioStream: null | MediaStream = null

userDenied: boolean
userDenied: boolean = false

recorder: null | MediaRecorder
recorder: null | MediaRecorder = null

outputStream: null | MediaStream
outputStream: null | MediaStream = null

recordingChunks: Blob[] | null
recordingChunks: Blob[] | null = null

constructor(uppy: Uppy<M, B>, opts?: ScreenCaptureOptions) {
super(uppy, { ...defaultOptions, ...opts })
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/screen-capture/src/StopWatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class StopWatch extends Component {
fontFamily: 'Courier New',
} as const

private timerRunning: boolean
private timerRunning: boolean = false

private timer: ReturnType<typeof setTimeout>
private timer: ReturnType<typeof setTimeout> | undefined

constructor(props: $TSFixMe) {
super(props)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/url/src/Url.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class Url<M extends Meta, B extends Body> extends UIPlugin<

client: RequestClient<M, B>

canHandleRootDrop: typeof canHandleRootDrop
canHandleRootDrop!: typeof canHandleRootDrop

constructor(uppy: Uppy<M, B>, opts: UrlOptions) {
super(uppy, opts)
Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/url/src/UrlUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type UrlUIProps = {
class UrlUI extends Component<UrlUIProps> {
form = document.createElement('form')

input: HTMLInputElement
// Ref is always defined after render
input!: HTMLInputElement

constructor(props: UrlUIProps) {
super(props)
Expand Down
10 changes: 5 additions & 5 deletions packages/@uppy/utils/src/RateLimitedQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export class RateLimitedQueue {

#paused = false

#pauseTimer: ReturnType<typeof setTimeout>
#pauseTimer: ReturnType<typeof setTimeout> | undefined

#downLimit = 1

#upperLimit: number
#upperLimit: number | undefined

#rateLimitingTimer: ReturnType<typeof setTimeout>
#rateLimitingTimer: ReturnType<typeof setTimeout> | undefined

limit: number

Expand Down Expand Up @@ -285,11 +285,11 @@ export class RateLimitedQueue {
return
}
this.#downLimit = this.limit
this.limit = Math.ceil((this.#upperLimit + this.#downLimit) / 2)
this.limit = Math.ceil((this.#upperLimit! + this.#downLimit) / 2)
for (let i = this.#downLimit; i <= this.limit; i++) {
this.#queueNext()
}
if (this.#upperLimit - this.#downLimit > 3) {
if (this.#upperLimit! - this.#downLimit > 3) {
this.#rateLimitingTimer = setTimeout(this.#increaseLimit, 2000)
} else {
this.#downLimit = Math.floor(this.#downLimit / 2)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/webcam/src/CameraScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface CameraScreenProps extends VideoSourceSelectProps {
}

class CameraScreen extends Component<CameraScreenProps> {
private videoElement: HTMLVideoElement
private videoElement: HTMLVideoElement | undefined

refs: any

Expand Down
10 changes: 5 additions & 5 deletions packages/@uppy/webcam/src/Webcam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ export default class Webcam<M extends Meta, B extends Body> extends UIPlugin<

private webcamActive

private stream: MediaStream | null
private stream: MediaStream | null = null

private recorder: MediaRecorder | null
private recorder: MediaRecorder | null = null

private recordingChunks: Blob[] | null
private recordingChunks: Blob[] | null = null

private recordingLengthTimer: ReturnType<typeof setInterval>
private recordingLengthTimer: ReturnType<typeof setInterval> | undefined

private captureInProgress: boolean
private captureInProgress: boolean = false

constructor(uppy: Uppy<M, B>, opts?: WebcamOptions<M, B>) {
super(uppy, { ...defaultOptions, ...opts })
Expand Down
9 changes: 3 additions & 6 deletions tsconfig.shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"composite": true,
"incremental": true,
"target": "ESnext",
"module": "ESNext",
"moduleResolution": "Bundler",
"module": "preserve",
"lib": ["dom", "ESnext"],
"resolveJsonModule": true,
"useUnknownInCatchVariables": false,
"allowImportingTsExtensions": true,
"allowJs": false,
"declaration": true,
Expand All @@ -16,11 +16,8 @@
"jsxImportSource": "preact",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strict": true,
"verbatimModuleSyntax": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strictFunctionTypes": true,
"forceConsistentCasingInFileNames": true
}
}

0 comments on commit 1fb5472

Please sign in to comment.