question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

collections: most functions that work on `Record` do not work with `interface`

See original GitHub issue

Most of collections’ functions that work on Record do not work with interface

To Reproduce

import { deepMerge, filterEntries } from "https://deno.land/std/collections/mod.ts";

interface Foo {
  bar: string;
}

const foo1: Foo = { bar: "deno" };
const foo2: Foo = { bar: "deno" };

const a = deepMerge(foo1, foo2);
const b = filterEntries(foo1, ([key]) => key !== "a");

Expected behavior

It compiles.

Current behaviour

It does not compile.

Argument of type 'Foo' is not assignable to parameter of type 'Record<PropertyKey, unknown>'.
      Index signature is missing in type 'Foo'

Desktop (please complete the following information):

deno 1.13.0 (release, x86_64-unknown-linux-gnu)
v8 9.3.345.11
typescript 4.3.5

Additional context Possible workaround is to use type instead of interface, but that’s not ideal:

type Foo = {
  bar: string;
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
LionCcommented, Aug 18, 2021

I agree with most, however 2 small points:

  • Prefer type over interface is highly debatable. [1][2]
  • type can also be extended: type Developer = Human & { usesVim: boolean }

There isn’t an elegant solution, but we can try to augment the type of functions that one might use on interfaces to help our users.

That is definitely debatable 😃

I do not think there is a reasonable solution on the API side though, so I would vote to close this issue.

0reactions
lino-levancommented, Oct 31, 2022

I think this issue should probably be closed, though the discussion in this issue is very interesting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Collection classes
The Collection interface contains generic methods for adding and removing objects, testing whether or not a given element is present in the collection, ......
Read more >
Collections In Java and How to Implement Them? [Updated]
Java Collections are the one-stop solutions for all the data manipulation jobs such as storing data, searching, sorting, insertion, ...
Read more >
The List Interface (The Java™ Tutorials > Collections ...
This collections Java tutorial describes interfaces, implementations, and algorithms in the Java Collections framework.
Read more >
collections — Container datatypes
Source code: Lib/collections/__init__.py This module implements specialized container datatypes providing alternatives to Python's general purpose built-in ...
Read more >
Interface vs record of functions
Interfaces express a different intention - they are interface that can be satisfied and implemented. On the other hand, records are collections ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found