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

Types include unresolved imports will be turned into any #54630

Closed
so1ve opened this issue Jun 13, 2023 · 9 comments
Closed

Types include unresolved imports will be turned into any #54630

so1ve opened this issue Jun 13, 2023 · 9 comments
Labels
Not a Defect This behavior is one of several equally-correct options

Comments

@so1ve
Copy link

so1ve commented Jun 13, 2023

Bug Report

πŸ”Ž Search Terms

any, unresolved

πŸ•— Version & Regression Information

  • This changed between versions 5.0.4 and 5.1.3

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
type PickNotAny<A, B> = IsAny<A> extends true ? B : A;

// @ts-ignore
type a = import('vue').GlobalComponents
//   ^?

type GlobalComponents =
//   ^?
	// @ts-ignore
	PickNotAny<import('vue').GlobalComponents, {}>

type GlobalComponents2 =
//   ^?
	// @ts-ignore
	PickNotAny<any, {}>

πŸ™ Actual behavior

Β―_(ツ)_/Β―

πŸ™‚ Expected behavior

They should not behave differently

@so1ve
Copy link
Author

so1ve commented Jun 13, 2023

Update: not right actually. Types include unresolved imports will be turned into any, no matter what they do. So a shorter demo: Link

@so1ve so1ve changed the title Unresolved "any" is not "any" Types include unresolved imports will be turned into any Jun 13, 2023
@johnsoncodehk
Copy link

Just for to make it clearer:

type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;

type A = IsAny<any>; // βœ… type A = true
type B = IsAny<import('vue').GlobalComponents>; // ❌ type B = any
type C = IsAny<import('vue').GlobalComponents & {}>; // βœ… type C = true

@so1ve
Copy link
Author

so1ve commented Jun 13, 2023

Just for to make it clearer:

type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;

type A = IsAny<any>; // βœ… type A = true
type B = IsAny<import('vue').GlobalComponents>; // ❌ type B = any
type C = IsAny<import('vue').GlobalComponents & {}>; // βœ… type C = true

Yes this also works! I can change my fix.

@RyanCavanaugh RyanCavanaugh added the Not a Defect This behavior is one of several equally-correct options label Jun 13, 2023
@RyanCavanaugh
Copy link
Member

There are no specific guarantees on what happens when there is an error type in your program.

@so1ve
Copy link
Author

so1ve commented Jun 13, 2023

That's true. However, the type of it is literally any, but it doesn't behave like any.

@RyanCavanaugh
Copy link
Member

The hover shows "any" for lack of a better thing to display. It could be differentiated, but these things tend to not stick around in programs very long.

@so1ve
Copy link
Author

so1ve commented Jun 13, 2023

Maybe you are right!
However I still prefer the former behavior. Typing it as any but it does not behave like any ismisleading. What's more, because volar imports the GlobalComponent interface from three different packages and the users maybe install one of them only (detecting whether they were installed without type system will increase workload), we rely on the former behavior to detect whether they were installed. If not, the interfaces are simply any and we can fallback to an empty interface. But in 5.1.3 we'll need a hack to fix that. In short, the old behavior is useful in some cases, but that in 5.1.3 is not intuitive.

@fatcerberus
Copy link

fatcerberus commented Jun 13, 2023

My suspicion is that any compile-time check that requires a @ts-ignore in the source to work at all will never be a supported use case. You are more or less in β€œundefined behavior” territory; here be dragons.

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Not a Defect' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Defect This behavior is one of several equally-correct options
Projects
None yet
Development

No branches or pull requests

5 participants