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

[undefined] is assignable to number[] #81

Open
louwers opened this issue Apr 16, 2022 · 0 comments
Open

[undefined] is assignable to number[] #81

louwers opened this issue Apr 16, 2022 · 0 comments

Comments

@louwers
Copy link

louwers commented Apr 16, 2022

Reproduction

import test from "ava";
import { isAssignableToValue, toSimpleType } from "../src";
import { Project } from "ts-morph";
import * as ts from "typescript";

function getType(source: string): [ts.Type, ts.TypeChecker] {
	const project = new Project({
		compilerOptions: {
			strict: true
		}
	});
	const typeChecker = project.getTypeChecker().compilerObject;

	project.createSourceFile("test.ts", source);
	const sourceFile = project.getSourceFile("test.ts")!;
	const typeAlias = sourceFile.getTypeAlias("Type");
	if (!typeAlias) throw new Error("type not found");
	return [typeAlias.getType().compilerType, typeChecker];
}

test("number[]", t => {
	const [type, typeChecker] = getType("type Type = number[]");

	t.truthy(isAssignableToValue(type, [1, 2, 3], typeChecker));
	t.truthy(isAssignableToValue(type, [], typeChecker));
	t.falsy(isAssignableToValue(type, [undefined], typeChecker));
});
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

No branches or pull requests

1 participant