Skip to content

Commit

Permalink
refactor(core): adjust typings
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jul 2, 2021
1 parent 04f5755 commit 23f1fa0
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/classes/src/lib/storages/class-instance.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ export class ClassInstanceStorage {
value: number
): void {
if (!storage.has(parent)) {
storage.set(parent, arrayMapSet(new Map(), member, value));
storage.set(parent, arrayMapSet(new Map(), member, value)!);
return;
}

if (!this.hasInternal(storage, parent, member)) {
arrayMapSet(storage.get(parent), member, value);
arrayMapSet(storage.get(parent)!, member, value);
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ function arrayMapHas(root: ArrayKeyedMap, path: string[]): boolean {
function arrayMapGet(root: ArrayKeyedMap, path: string[]): number | undefined {
let map = root;
for (const item of path) {
map = (map as PathMap).get(item);
map = (map as PathMap).get(item)!;
if (!map) return undefined;
}
return (map as DataMap).get(DATA_SYMBOL);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/create-mapper/create-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function createMapper<TKey = unknown>({
: [];

// get mapping between Source and Destination
const mapping: Mapping = this.getMapping(source, destination);
const mapping: Mapping | undefined = this.getMapping(source, destination);

// check mutate or return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const PROXY_OBJECT = createProxy(PROXY_TARGET);
* @returns `null` if the given `fnSelector` doesn't match with anything.
*/
export function getMembers(
fnSelector: Selector<unknown, unknown | (() => string[])>
fnSelector: Selector<any, any | (() => string[])>
): string[] | null {
const resultProxy = fnSelector(PROXY_OBJECT) as () => string[];
if (typeof resultProxy !== 'function') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export function createInitialMapping(
}

// Inherit base mappings
extendMappings(bases, mapping);
if (bases.length) {
extendMappings(bases as Mapping[], mapping!);
}

saveMapping(mapping);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getFlatteningSourcePaths(
namingConventions: [NamingConvention, NamingConvention]
): string[] | undefined {
const [sourceNamingConvention] = namingConventions;
const splitSourcePaths: string[] = [].concat(
const splitSourcePaths: string[] = ([] as string[]).concat(
...srcPath.map((s) =>
s.split(sourceNamingConvention.splittingExpression).filter(Boolean)
)
Expand Down Expand Up @@ -38,7 +38,7 @@ export function getFlatteningSourcePaths(
return;
}

return [].concat(
return ([] as string[]).concat(
trueFirstPartOfSource,
sourceNamingConvention.transformPropertyName(
splitSourcePaths.slice(stopIndex + 1, splitSourcePaths.length + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getPathRecursive(
const keys = Object.getOwnPropertyNames(node);
for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i];
const path: string[] = [].concat(...prefix, key);
const path: string[] = ([] as string[]).concat(...prefix, key);
result.push(path);

const child = node[key];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/utils/get.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function get<T>(object: T, path: (string | symbol)[] = []): unknown {
const length = path.length;

for (index = 0; index < length && object != null; index++) {
object = object[path[index]];
object = (object as Record<string, unknown>)[path[index] as string] as T;
}

return index && index == length ? object : undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/utils/set.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function decomposePath(path: string[]): {
base: string;
} {
if (path.length < 1) {
return { base: undefined, decomposedPath: undefined };
return { base: '', decomposedPath: [] };
}
const decomposedPath = path;
const base = path[0];
Expand Down

0 comments on commit 23f1fa0

Please sign in to comment.