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

Function parameter that has inferred type has no intellisense in the return , while it has in the rest of the function body #38748

Open
ghost opened this issue May 23, 2020 · 1 comment
Labels
Bug A bug in TypeScript
Milestone

Comments

@ghost
Copy link

ghost commented May 23, 2020

TypeScript Version: 3.9.2

Search Terms: generic , intellisense , infered type

Code:

/*
This function will be used in javascript projects.
I want its intellisense to work in javascript projects.
*/
function component<T>(p: {
	actions : () => T,
	htmlTemplate: <S extends T>(actions : S) => any
}) {
	return p;
}

component({
	actions : () => ({
		a : (x,y) => x+y
	}),
	htmlTemplate : (actions) => { 
		/*try to dot into the actions and you will get intellisense*/ 
		actions;
		/*but if you dot here you will get no intellisense*/ 
		return actions;
		/*
		Intellisense appears in the `return actions` If I type `x` and `y`.
		Strangely it works if I explicitly type them with `any`
		but it does not work if I they are implicilty typed with `any` .
		How can I have no problem with intellisense with implicit `any`?
		*/
	}
})

Expected behavior: Implicit any should have the same effect on intellisense with explicit any .

Actual behavior: Implicit any is different from explicit any .

Playground Link: link

@ghost
Copy link
Author

ghost commented May 24, 2020

off topic but an ugly "solution" is to do this :

const component = <T>(p1: {
	actions: () => T
}) => (p2: {
	htmlTemplate: <S extends T>(actions: S) => any
}) => Object.assign({}, p1, p2)

component({
	actions: () => ({
		a: (x, y) => x + y
	})
})({
	htmlTemplate: (actions) => {
		actions;
		return actions;
	}
});

and there is no problem with intellisense .

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 11, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant