8000 Add compiler option to require explicit casts from any to other types · Issue #22716 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Add compiler option to require explicit casts from any to other types #22716
@wolverian

Description

@wolverian

TypeScript Version: typescript@2.8.0-dev.20180320

Search Terms: explicit any conversion

Code

function x(): any {
	return 42
}

const y: string = x()

Expected behavior: I can use a compiler option to require an explicit cast from any to string, and the code above would give an error with that option enabled. Function x in the example usually comes from a library definition file like: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/9f4c75126167d0d8af759f58405d53d983e94ad0/types/yargs/index.d.ts#L226

Actual behavior: There is no such option.

Playground Link: http://www.typescriptlang.org/play/index.html#src=function%20x()%3A%20any%20%7B%0D%0A%20%20%20%20return%2042%0D%0A%7D%0D%0A%0D%0Aconst%20y%3A%20string%20%3D%20x()

Related Issues: #22464 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0