Skip to content
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

Fix TypeScript errors in lib/utils #231

Open
wants to merge 1 commit into
base: ts-fixes
Choose a base branch
from

Conversation

rgieseke
Copy link
Contributor

This fixes a few more TypeScript errors, those in lib/utils (see #218).

The error messages were:

src/lib/utils/makeAccessor.js:4:33
Error: Generic type 'Array<T>' requires 1 type argument(s). 
	Make an accessor from a string, number, function or an array of the combination of any
	@param {string|number|Function|Array} acc The accessor function, key or list of them.
	@returns {Function} An accessor function.
--
src/lib/utils/makeAccessor.js:8:23
Error: Type 'null' is not assignable to type 'Function'. 
export default function makeAccessor(acc) {
	if (!canBeZero(acc)) return null;
	if (Array.isArray(acc)) {
--
src/lib/utils/makeAccessor.js:10:10
Error: Parameter 'd' implicitly has an 'any' type. 
	if (Array.isArray(acc)) {
		return d =>
			acc.map(k => {
--
src/lib/utils/makeAccessor.js:15:10
Error: Parameter 'd' implicitly has an 'any' type. 
	} else if (typeof acc !== 'function') {
		return d => d[acc];
	}
--
src/lib/utils/filterObject.js:10:34
Error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  No index signature with a parameter of type 'string' was found on type '{}'. 
		Object.entries(obj).filter(([key, value]) => {
			return value !== undefined && comparisonObj[key] === undefined;
--
src/lib/utils/debounce.js:8:6
Error: Variable 'timer' implicitly has type 'any' in some locations where its type cannot be determined. 
export default function debounce(func, timeout = 300) {
	let timer;
	return (...args) => {
--
src/lib/utils/debounce.js:9:10
Error: Rest parameter 'args' implicitly has an 'any[]' type. 
	let timer;
	return (...args) => {
		clearTimeout(timer);
--
src/lib/utils/debounce.js:10:16
Error: Variable 'timer' implicitly has an 'any' type. 
	return (...args) => {
		clearTimeout(timer);
		timer = setTimeout(() => {
--
src/lib/utils/debounce.js:12:15
Error: 'this' implicitly has type 'any' because it does not have a type annotation. 
		timer = setTimeout(() => {
			func.apply(this, args);
		}, timeout);
--
src/lib/utils/arraysEqual.js:6:10
Error: Generic type 'Array<T>' requires 1 type argument(s). 
	of making a set
	@param {Array} arr1 An array to test
	@param {Array} arr2 An array to test against
--
src/lib/utils/arraysEqual.js:7:10
Error: Generic type 'Array<T>' requires 1 type argument(s). 
	@param {Array} arr1 An array to test
	@param {Array} arr2 An array to test against
	@returns {boolean} Whether they contain all and only the same items
--
src/lib/utils/padScale.js:19:34
Error: Parameter 'scale' implicitly has an 'any' type. 

export default function padScale(scale, padding) {
	if (typeof scale.range !== 'function') {
--
src/lib/utils/padScale.js:19:41
Error: Parameter 'padding' implicitly has an 'any' type. 

export default function padScale(scale, padding) {
	if (typeof scale.range !== 'function') {
--
src/lib/utils/padScale.js:41:38
Error: Parameter 'd' implicitly has an 'any' type. 

	const [d1, d2] = scale.domain().map(d => {
		return isTime ? lift(d.getTime()) : lift(d);

const unpaddable = ['scaleThreshold', 'scaleQuantile', 'scaleQuantize', 'scaleSequentialQuantile'];

/**
* @typedef {import('d3-scale').ScaleLinear<any, any> |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I went through the d3-docs and added the interface definitions.

Not sure whether one should exclude those that are filtered out with unpaddable or whether there is already combinations like scaleContinuousNumeric which would make the list shorter.

*/
export default function debounce(func, timeout = 300) {
const debounce = (func, timeout = 300) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this to an arrow function was the solution I found to this not being defined.

@mhkeller
Copy link
Owner

Thanks for this one. I was away for a few weeks and will go through this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants