Skip to content

Commit

Permalink
Upgrade to latest TypeScript version and fixed issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lnewson committed May 10, 2021
1 parent 9489b69 commit 23f7520
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 35 deletions.
15 changes: 9 additions & 6 deletions modules/agar/src/main/ts/ephox/agar/datatransfer/DataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { getData } from './DataTransferItem';
import { createDataTransferItemList } from './DataTransferItemList';
import { isInProtectedMode, isInReadWriteMode, setReadWriteMode } from './Mode';

type DropEffect = DataTransfer['dropEffect'];
type EffectAllowed = DataTransfer['effectAllowed'];

const imageId = Id.generate('image');

const validDropEffects = [ 'none', 'copy', 'link', 'move' ];
const validEffectAlloweds = [ 'none', 'copy', 'copyLink', 'copyMove', 'link', 'linkMove', 'move', 'all', 'uninitialized' ];
const validDropEffects: DropEffect[] = [ 'none', 'copy', 'link', 'move' ];
const validEffectAlloweds: EffectAllowed[] = [ 'none', 'copy', 'copyLink', 'copyMove', 'link', 'linkMove', 'move', 'all', 'uninitialized' ];

export interface DragImageData {
image: Element;
Expand Down Expand Up @@ -38,15 +41,15 @@ const normalize = (format: string) => {
};

const createDataTransfer = (): DataTransfer => {
let dropEffect = 'move';
let effectAllowed = 'all';
let dropEffect: DropEffect = 'move';
let effectAllowed: EffectAllowed = 'all';

const dataTransfer: DataTransfer = {
get dropEffect() {
return dropEffect;
},

set dropEffect(effect: string) {
set dropEffect(effect: DropEffect) {
if (Arr.contains(validDropEffects, effect)) {
dropEffect = effect;
}
Expand All @@ -56,7 +59,7 @@ const createDataTransfer = (): DataTransfer => {
return effectAllowed;
},

set effectAllowed(allowed: string) {
set effectAllowed(allowed: EffectAllowed) {
if (Arr.contains(validEffectAlloweds, allowed)) {
effectAllowed = allowed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ UnitTest.test('DataTransfer: setEffects', () => {
transfer.dropEffect = 'copy';
Assert.eq('Should be expected new value', 'copy', transfer.dropEffect);

transfer.dropEffect = 'xyz';
transfer.dropEffect = 'xyz' as any;
Assert.eq('Should be unchanged', 'copy', transfer.dropEffect);

transfer.effectAllowed = 'copyLink';
Assert.eq('Should be expected new value', 'copyLink', transfer.effectAllowed);

transfer.effectAllowed = 'xyz';
transfer.effectAllowed = 'xyz' as any;
Assert.eq('Should be unchanged', 'copyLink', transfer.effectAllowed);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const setDragImage = (transfer: DataTransfer, image: Element, x: number, y: numb
}
};

const setDropEffect = (transfer: DataTransfer, effect: string): void => {
const setDropEffect = (transfer: DataTransfer, effect: DataTransfer['dropEffect']): void => {
transfer.dropEffect = effect;
};

const setEffectAllowed = (transfer: DataTransfer, effect: string): void => {
const setEffectAllowed = (transfer: DataTransfer, effect: DataTransfer['effectAllowed']): void => {
transfer.effectAllowed = effect;
};

Expand All @@ -81,7 +81,7 @@ const getDataTransferFromEvent = (simulatedEvent: NativeSimulatedEvent<DragEvent
return rawEvent.dataTransfer as DataTransfer;
};

const setDropEffectOnEvent = (simulatedEvent: NativeSimulatedEvent<DragEvent>, dropEffect: string): void => {
const setDropEffectOnEvent = (simulatedEvent: NativeSimulatedEvent<DragEvent>, dropEffect: DataTransfer['dropEffect']): void => {
setDropEffect(getDataTransferFromEvent(simulatedEvent), dropEffect);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface StartingDragndropConfigSpec {
export interface DragStartingConfig {
type: string;
phoneyTypes: string[];
effectAllowed: string;
effectAllowed: DataTransfer['effectAllowed'];
getData: Optional<(component: AlloyComponent) => string>;
getImageParent: Optional<(component: AlloyComponent) => SugarElement>;
getImage: Optional<(component: AlloyComponent) => DragnDropImageClone>;
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface DropDragndropConfigSpec {

export interface DroppingConfig {
type: string;
dropEffect: string;
dropEffect: DataTransfer['dropEffect'];
onDrop: (component: AlloyComponent, dropEvent: DropEvent) => void;
onDrag: (component: AlloyComponent, simulatedEvent: NativeSimulatedEvent) => void;
onDragover: (component: AlloyComponent, simulatedEvent: NativeSimulatedEvent) => void;
Expand Down
2 changes: 1 addition & 1 deletion modules/jax/src/main/ts/ephox/jax/core/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const fetchDownload = (init: HttpTypes.DownloadHttpRequest): FutureResult<Blob,

if (body) {
const reader = body.getReader();
const process = (result: ReadableStreamReadResult<Uint8Array>) => {
const process = (result: ReadableStreamDefaultReadResult<Uint8Array>) => {
if (result.done) {
resolve(Result.value(new Blob(chunks, { type: mime.getOr('') })));
} else {
Expand Down
5 changes: 4 additions & 1 deletion modules/katamari/src/main/ts/ephox/katamari/api/Future.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ const make = <T = any>(run: () => Promise<T>): Future<T> => {

};

const nu = <T = any>(baseFn: (completer: (value?: T) => void) => void): Future<T> => {
const nu: {
<T = any>(baseFn: (completer: (value: T) => void) => void): Future<T>;
(baseFn: (completer: () => void) => void): Future<void>;
} = <T = any>(baseFn: (completer: (value?: T) => void) => void): Future<T | void> => {
return make(() => new Promise(baseFn));
};

Expand Down
2 changes: 1 addition & 1 deletion modules/katamari/src/main/ts/ephox/katamari/api/Futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Arr from './Arr';
import { Future } from './Future';

export const par = <T>(futures: ArrayLike<Future<T>>): Future<Array<T>> =>
AsyncValues.par(futures, Future.nu);
AsyncValues.par<Future<T>, T, Future<Array<T>>>(futures, Future.nu);

export const traverse = <A, B>(array: ArrayLike<A>, fn: (value: A) => Future<B>): Future<B[]> =>
par(Arr.map(array, fn));
Expand Down
4 changes: 2 additions & 2 deletions modules/katamari/src/test/ts/atomic/api/async/FutureTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ promiseTest('Future: parallel', () => new Promise((resolve, reject) => {
eqAsync('r[0]', r[0], 'apple', reject);
eqAsync('r[1]', r[1], 'banana', reject);
eqAsync('r[2]', r[2], 'carrot', reject);
resolve(true);
resolve();
});
}));

Expand Down Expand Up @@ -129,7 +129,7 @@ promiseTest('Future: compose', () => {

Futures.compose(f, g)('a').get((r) => {
eqAsync('compose', 'a g f', r, reject);
resolve(true);
resolve();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Testable<A> = Testable.Testable<A>;
* @param name
* @param f
*/
export const promiseTest = <A>(name: string, f: () => Promise<A>): void => {
export const promiseTest = (name: string, f: () => Promise<void>): void => {
UnitTest.asynctest(name, (success, failure) => {
f().then(success, failure);
});
Expand Down
2 changes: 1 addition & 1 deletion modules/sugar/src/main/ts/ephox/sugar/api/dom/DomFuture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ const cWaitFor = (element: SugarElement, eventType: string, timeout: number): La
w(LazyValue.nu, element, eventType, timeout);

const waitFor = (element: SugarElement, eventType: string, timeout: number): Future<Result<EventArgs, string>> =>
w(Future.nu, element, eventType, timeout);
w<Future<Result<EventArgs, string>>>(Future.nu, element, eventType, timeout);

export { cWaitFor, waitFor };
2 changes: 1 addition & 1 deletion modules/sugar/src/test/ts/atomic/RectTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UnitTest } from '@ephox/bedrock-client';
import Jsc from '@ephox/wrap-jsverify';
import { Rect } from 'ephox/sugar/api/selection/Rect.ts';
import { Rect } from 'ephox/sugar/api/selection/Rect';

UnitTest.test('Rect', () => {
Jsc.property(
Expand Down
2 changes: 1 addition & 1 deletion modules/tinymce/src/core/main/ts/api/util/Delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const Delay: Delay = {
return;
}

requestAnimationFramePromise = new Promise((resolve) => {
requestAnimationFramePromise = new Promise<void>((resolve) => {
if (!element) {
element = document.body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('browser.tinymce.core.dom.ReferrerPolicyTest', () => {
assert.equal(links.length > 0, expected, `should have link with referrerpolicy="${referrerPolicy}"`);
};

const pLoadScript = (url: string) => new PromisePolyfill((resolve, reject) => {
const pLoadScript = (url: string): Promise<void> => new PromisePolyfill((resolve, reject) => {
ScriptLoader.ScriptLoader.loadScript(url, resolve, () => reject('Failed to load script'));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('browser.tinymce.core.dom.ScriptLoaderTest', () => {
let loadedScripts: string[] = [];
let loadedCount = 0;

const pLoadScript = (url: string) => {
const pLoadScript = (url: string): Promise<void> => {
loadedScripts.push(url);
return new PromisePolyfill((resolve, reject) => {
ScriptLoader.ScriptLoader.loadScript(url, () => {
Expand All @@ -20,7 +20,7 @@ describe('browser.tinymce.core.dom.ScriptLoaderTest', () => {
});
};

const pLoadScripts = (urls: string[]) => {
const pLoadScripts = (urls: string[]): Promise<void> => {
loadedScripts.push(...urls);
const scriptCount = urls.length;
return new PromisePolyfill((resolve, reject) => {
Expand All @@ -31,12 +31,12 @@ describe('browser.tinymce.core.dom.ScriptLoaderTest', () => {
});
};

const addToQueue = (url: string) => {
const addToQueue = (url: string): void => {
loadedScripts.push(url);
ScriptLoader.ScriptLoader.add(url, () => loadedCount++);
};

const pLoadQueue = () => new PromisePolyfill((resolve, reject) => {
const pLoadQueue = (): Promise<void> => new PromisePolyfill((resolve, reject) => {
ScriptLoader.ScriptLoader.loadQueue(resolve, undefined, () => reject('Failed to load queued scripts'));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe('browser.tinymce.core.dom.StyleSheetLoaderTest', () => {

const linkNotExists = (url: string) => UiFinder.notExists(SugarHead.head(), `link[href="${url}"]`);

const pLoadUrl = (url: string) => new PromisePolyfill((resolve, reject) => {
const pLoadUrl = (url: string): Promise<void> => new PromisePolyfill((resolve, reject) => {
loader.load(url, resolve, () => reject('Failed to load url: ' + url));
});

const pLoadAllUrls = (urls: string[]) => new PromisePolyfill((resolve, reject) => {
const pLoadAllUrls = (urls: string[]): Promise<string[]> => new PromisePolyfill((resolve, reject) => {
loader.loadAll(urls, resolve, (failedUrls) => reject('Failed to load urls: ' + failedUrls.join(', ')));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ UnitTest.asynctest('browser.tinymce.plugins.paste.ImagePasteTest', (success, fai
return editor.selection.getRng();
};

const waitFor = (predicate: () => boolean) => {
const waitFor = (predicate: () => boolean): Promise<void> => {
return new Promise((resolve, reject) => {
const check = (time, count) => {
if (predicate()) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"tsconfig-paths-webpack-plugin": "^3.2.0",
"tslib": "^2.0.0",
"twemoji": "^13.0.1",
"typescript": "^4.0.5",
"typescript": "^4.2.4",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11575,10 +11575,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^4.0.0, typescript@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
typescript@^4.0.0, typescript@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==

typical@^4.0.0:
version "4.0.0"
Expand Down

0 comments on commit 23f7520

Please sign in to comment.