MhMadHamster
Repos
60
Followers
11

Events

opened issue
It is possible to change variance of type parameter from invariant to covariant

Bug Report

🔎 Search Terms

variance, invariant, covariant, out

🕗 Version & Regression Information

  • I was unable to test this on prior versions because out modifier was added in 4.7

⏯ Playground Link

Playground link with relevant code

💻 Code

interface Animal {
	run(): void;
};

class Dog implements Animal {
	run() {};
	bark() {};
}

// this should not be possible, since T used both in input and output positions
interface Controller<out T> {
	createAnimal: () => T;
	run: (animal: T) => void;
}

class AnimalContainer<T extends Animal> {
	public constructor(public controller: Controller<T>) { }
}

function getAnimal(): AnimalContainer<Animal> {
    return new AnimalContainer({
		createAnimal() {
			return new Dog();
		},
		run(_animal) {}
	});
}

🙁 Actual behavior

You can change variance by adding out keyword to Controller interface which changes variance on T from invariant to covariant and that leads to no error in getAnimal function.

🙂 Expected behavior

When you try to change variance of Controller on T it should show an error Type 'Controller<sub-T>' is not assignable to type 'Controller<super-T>' as implied by variance annotation.

Created at 1 week ago
[Fix][dynamic-import-chunkname] Handle webpack magic comments

@ljharb hey, can you please take a look, when you will have time

Created at 2 months ago

add handling webpack magic comments

show webpackChunkName format error only when webpackChunkName invalid

update changelog

Created at 2 months ago

[Fix] named/ExportMap: handle named imports from CJS modules that use dynamic import

Fix #2294

Mark ambiguous (i.e. not unambiguously ESM) modules that contain dynamic import() so that they can be ignored like other ambiguous modules when analysing named imports.

In this way, the named rule accepts named imports from CJS modules that contain dynamic imports.

Also fix the case where the importing module uses a require() call.

[utils] [patch] Fix @babel/eslint-parser 8 compatibility

[utils] [Refactor] inline pkgDir implementation; remove pkg-dir

utils: v2.7.2

[Deps] update eslint-module-utils

[Dev Deps] update safe-publish-latest

Bump to v2.25.4

[utils] [Fix] parse: restore compatibility by making the return value ast again

Fixes #2350

[Deps] update is-core-module, resolve

[Tests] no-nodejs-modules: add tests for node protocol URL

[Tests] configure ESLint overrides to parse arbitrary module namespace names

[Tests] default, no-anonymous-default-export, no-mutable-exports, no-named-as-default-member, no-named-as-default: add tests for arbitrary module namespace names

[New] no-named-default: support arbitrary module namespace names

[New] no-default-export: support arbitrary module namespace names

[New] prefer-default-export: support arbitrary module namespace names

[New] no-named-export: support arbitrary module namespace names

[New] export: support arbitrary namespace names

[New] named: support arbitrary module namespace names

[New] namespace: support arbitrary module namespace names

[New] no-unused-modules: support arbitrary module namespace names

Created at 2 months ago