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

Typescript = Javascript + Commented Types. noImplicitAny doesn't work with jsdoc types #10033

Closed
nojvek opened this issue Jul 29, 2016 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@nojvek
Copy link
Contributor

nojvek commented Jul 29, 2016

TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)

Code

/**
 * @param {string} cmd - command to execute
 */
function exec(cmd) {
  execSync(cmd)
}

Expected behavior:

Type of cmd should be string

Actual behavior:

Type of cmd is any and compiler gives error.

/** @type string */
const hello

Still gives no implicitError.

Weird thing is if my file is .js then tsc doesn't do any type checking or give me useful errors.

The user scenario is:

  • I want to use tsc to typecheck and VSCode to provide excellent code complete/refactoring
  • I don't want to transpile since I'm already using ES6. I just want the IDE experience
  • I want my typescript type specific information defined as jsdoc or flow like comments.
  • Typescript is Javascript + Types. It should also work for Javascript + Commented Types.
@nojvek nojvek changed the title l[ojkiklnugfytfggr56tvbgyufg76rtkyujo;kl';iuoijkl;p='[] noImplicityAny: true should not give an error when types are defined using jsdoc Jul 29, 2016
@nojvek nojvek changed the title noImplicityAny: true should not give an error when types are defined using jsdoc Typescript = Javascript + Commented Types. noImplicitAny doesn't work with jsdoc types Jul 29, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Dec 15, 2016

There is one way to write types in a .ts file, and that is type annotations. JSDoc comments are not relevant here. in a .js file it can be used, and it is. but --noImplicitAny is not relevant there really.

@mhegazy mhegazy closed this as completed Dec 15, 2016
@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 15, 2016
@nojvek
Copy link
Contributor Author

nojvek commented Dec 16, 2016 via email

@mhegazy
Copy link
Contributor

mhegazy commented Dec 16, 2016

So this means typescript cannot be used a pure type validator for js files.

it can, and it does. the file extension needs to be .js.

A big usecase is just adding types to javascript function parameters.

this works in VS Code / VS 2017 today. just open a .js file add jsdoc comments and you should be able to use them. you can use them in your typescript compilation using --allowjs.

All the type errors are suppressed in a .js file, but this is tracked by #6802

@jcrben
Copy link

jcrben commented Nov 23, 2017

for posterity, it seems --noImplicitAny isn't really recommended in js per #14617 altho it's still around... looks like jsdoc annotations don't work.

bit tough for js and ts to coexist with these options but oh well

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants