Skip to content

compiler option to fallback to unknown instead of any when failing to resolve a typeΒ #46330

Open
@DetachHead

Description

@DetachHead

Suggestion

πŸ” Search Terms

unknown instead of any error

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

currently, when a type fails to resolve, there's an error in an external lib suppressed by skipLibCheck, or an error suppressed by @ts-expect-error/@ts-ignore, the type falls back to any

it would be nice if there was a compiler option that changes this behavior to unknown instead of any. it would make this feature even more useful too

πŸ“ƒ Motivating Example

currently, @ts-ignore and @ts-expect-error comments aren't exposed in .d.ts files. one of the concerns with changing this functionality seems to be that it can result in any leaking into the codebase (see #38628 (comment)).

πŸ’» Use Cases

  • makes it safer to use skipLibCheck, for example if a lib was compiled using a different version of typescript which causes errors on the version you're using
  • makes it a little bit safer to use @ts-expect-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions