Skip to content

Commit 2471fc3

Browse files
committed
Add more strict typing
1 parent 0c4be5b commit 2471fc3

File tree

13 files changed

+52
-26
lines changed

13 files changed

+52
-26
lines changed

packages/app/src/app/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ import HTML5Backend from './pages/common/HTML5BackendWithFolderSupport';
3737

3838
const debug = _debug('cs:app');
3939

40+
/**
41+
* Get rid of a tippy warning that spams the console, and doesn't seem valid.
42+
*/
43+
const warn = console.warn;
44+
console.warn = (...args) => {
45+
if (args[0].includes('Cannot update plugins')) {
46+
return;
47+
}
48+
49+
warn(...args);
50+
};
51+
4052
window.setImmediate = (func, delay) => setTimeout(func, delay);
4153

4254
window.addEventListener('unhandledrejection', e => {

packages/app/src/app/overmind/namespaces/editor/state.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
SandboxFs,
1717
Tabs,
1818
WindowOrientation,
19+
Directory,
1920
} from '@codesandbox/common/lib/types';
2021
import { getSandboxOptions } from '@codesandbox/common/lib/url';
2122
import { CollaboratorFragment, InvitationFragment } from 'app/graphql/types';
@@ -278,7 +279,11 @@ export const state: State = {
278279
};
279280

280281
// This should be moved somewhere else
281-
function getModuleParents(modules, directories, id): string[] {
282+
function getModuleParents(
283+
modules: Module[],
284+
directories: Directory[],
285+
id: string
286+
): string[] {
282287
const module = modules.find(moduleEntry => moduleEntry.id === id);
283288

284289
if (!module) return [];
@@ -288,9 +293,9 @@ function getModuleParents(modules, directories, id): string[] {
288293
);
289294
let directoryIds: string[] = [];
290295
while (directory != null) {
291-
directoryIds = [...directoryIds, directory.id];
296+
directoryIds = [...directoryIds, directory!.id];
292297
directory = directories.find(
293-
directoryEntry => directoryEntry.shortid === directory.directoryShortid // eslint-disable-line
298+
directoryEntry => directoryEntry.shortid === directory!.directoryShortid // eslint-disable-line
294299
);
295300
}
296301

packages/app/src/app/overmind/namespaces/files/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export const directoryMovedToDirectory: AsyncAction<{
267267
);
268268

269269
export const directoryDeleted: AsyncAction<{
270-
directoryShortid;
270+
directoryShortid: string;
271271
}> = withOwnedSandbox(
272272
async ({ state, actions, effects }, { directoryShortid }) => {
273273
const sandbox = state.editor.currentSandbox;

packages/app/src/app/overmind/namespaces/files/internalActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export const uploadFiles: AsyncAction<
7676
directories: any;
7777
}
7878
> = async ({ effects }, { files, directoryShortid }) => {
79-
const parsedFiles = {};
79+
const parsedFiles: {
80+
[key: string]: { isBinary: boolean; content: string };
81+
} = {};
8082
// We first create chunks so we don't overload the server with 100 multiple
8183
// upload requests
8284
const filePaths = Object.keys(files);

packages/app/src/app/overmind/namespaces/live/state.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type State = {
2929
liveUsersByModule: Derive<
3030
State,
3131
{
32-
[id: string]: string[];
32+
[id: string]: number[][];
3333
}
3434
>;
3535
};
@@ -76,7 +76,7 @@ export const state: State = {
7676
currentState.roomInfo?.ownerIds.includes(currentState.liveUserId)
7777
),
7878
liveUsersByModule: currentState => {
79-
const usersByModule = {};
79+
const usersByModule: { [id: string]: number[][] } = {};
8080

8181
if (!currentState.isLive || !currentState.roomInfo) {
8282
return {};
@@ -86,7 +86,7 @@ export const state: State = {
8686

8787
currentState.roomInfo.users.forEach(user => {
8888
const userId = user.id;
89-
if (userId !== liveUserId && user.currentModuleShortid) {
89+
if (user && userId !== liveUserId && user.currentModuleShortid) {
9090
usersByModule[user.currentModuleShortid] =
9191
usersByModule[user.currentModuleShortid] || [];
9292
usersByModule[user.currentModuleShortid].push(user.color);

packages/app/src/app/overmind/onInitialize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ export const onInitialize: OnInitialize = async (
8787
onViewRangeChanged: actions.live.onViewRangeChanged,
8888
onCommentClick: actions.comments.onCommentClick,
8989
reaction: overmindInstance.reaction,
90-
getState: path =>
90+
getState: (path: string) =>
9191
path ? path.split('.').reduce((aggr, key) => aggr[key], state) : state,
92-
getSignal: path =>
92+
getSignal: (path: string) =>
9393
path.split('.').reduce((aggr, key) => aggr[key], actions),
9494
});
9595

packages/app/src/app/overmind/utils/common.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Module } from '@codesandbox/common/lib/types';
22
import { fromPairs, sortBy, toPairs } from 'lodash-es';
33

4-
export function sortObjectByKeys(object) {
4+
export function sortObjectByKeys(object: object) {
55
return fromPairs(sortBy(toPairs(object)));
66
}
77

@@ -25,7 +25,11 @@ export function createOptimisticModule(overrides: Partial<Module>) {
2525
};
2626
}
2727

28-
export function lineAndColumnToIndex(lines, lineNumber, column) {
28+
export function lineAndColumnToIndex(
29+
lines: string[],
30+
lineNumber: number,
31+
column: number
32+
) {
2933
let currentLine = 0;
3034
let index = 0;
3135

@@ -40,7 +44,7 @@ export function lineAndColumnToIndex(lines, lineNumber, column) {
4044
return index;
4145
}
4246

43-
export function indexToLineAndColumn(lines, index) {
47+
export function indexToLineAndColumn(lines: string[], index: number) {
4448
let offset = 0;
4549
for (let i = 0; i < lines.length; i++) {
4650
const line = lines[i];

packages/app/src/app/overmind/utils/event-to-transform.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { TextOperation } from 'ot';
33
import { lineAndColumnToIndex } from './common';
44

55
export default function convertChangeEventToOperation(
6-
changeEvent,
7-
liveOperationCode
6+
changeEvent: any,
7+
liveOperationCode: string
88
) {
9-
let otOperation;
9+
let otOperation: TextOperation;
1010

1111
let composedCode = liveOperationCode;
1212

@@ -38,13 +38,13 @@ export default function convertChangeEventToOperation(
3838
newOt.retain(remaining);
3939
}
4040

41-
otOperation = otOperation ? otOperation.compose(newOt) : newOt;
41+
otOperation = otOperation! ? otOperation!.compose(newOt) : newOt;
4242

43-
composedCode = otOperation.apply(liveOperationCode);
43+
composedCode = otOperation!.apply(liveOperationCode);
4444
}
4545

4646
return {
47-
operation: otOperation,
47+
operation: otOperation!,
4848
newCode: composedCode,
4949
};
5050
}

packages/app/src/app/overmind/utils/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Sandbox } from '@codesandbox/common/lib/types';
44

55
import { resolveModuleWrapped } from './resolve-module-wrapped';
66

7-
export const getModuleCode = (sandbox: Sandbox, prettierConfig) => {
7+
export const getModuleCode = (sandbox: Sandbox, prettierConfig: unknown) => {
88
const path = getModulePath(sandbox.modules, sandbox.directories, module.id);
99
const template = getDefinition(sandbox.template);
1010
const config = template.configurationFiles[path];

packages/app/src/app/overmind/utils/pushToAirtable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export default async ({
66
email,
77
version,
88
browser,
9+
}: {
10+
[key: string]: string;
911
}) => {
1012
const Airtable = await import(
1113
/* webpackChunkName: 'airtable' */ './setAirtable'

0 commit comments

Comments
 (0)