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

Investigation of Unbound Type Parameters #118

Open
sgehly opened this issue Nov 25, 2021 · 0 comments
Open

Investigation of Unbound Type Parameters #118

sgehly opened this issue Nov 25, 2021 · 0 comments

Comments

@sgehly
Copy link

sgehly commented Nov 25, 2021

I was recently looking at #115 and I'm wondering if it may be possible to expand it into supporting nested & unbound parameter types. I know this is part of the "What it wont do" section, but it may be nice to investigate.

Here's a potential test that currently fails due to an unbounded type parameter:

import * as assert from 'assert';
import { assertType } from '../index';

type TestType = {
	name: string
}

type TestTypeTwo = {
	age: number
}

const deepDiveThree = <C>(body: unknown): C => {
	return assertType<C>(body)
}

const deepDiveTwo = <B>(body: unknown): B => {
	return deepDiveThree<B>(body)
}

const deepDive = <A>(body: unknown): A => {
	return deepDiveTwo<A>(body)
}

describe('is', () => {
	describe('Creating a generic assert type', () => {
		it('should not panic', () => {
			assert.deepEqual(deepDive<TestType>({ name: 'test' }).name, 'test')
			assert.deepEqual(deepDive<TestTypeTwo>({ age: 90 }).age, 90)
		});
	});
});

Unfortunately I don't have the technical know-how of typescript transformers to implement this myself yet, but I'm wondering if anyone had any pointers or if it's possible to resolve C up the chain through B and A to TestType and TestTypeTwo, while keeping in mind it may resolve to multiple different concrete types.

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