Skip to content

Compile error using TypeScript "ReturnType" #24499

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

Closed
jmagaram opened this issue Jun 14, 2018 · 6 comments
Closed

Compile error using TypeScript "ReturnType" #24499

jmagaram opened this issue Jun 14, 2018 · 6 comments

Comments

@jmagaram
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

Create a brand new Angular app. Open in VS Code. Compiles and works fine. Add the following legal TypeScript to a new .ts file in the app folder.

const f = () => 'abc';
type T = ReturnType<typeof f>;

Run npm build. Error I receive is `error TS2304: Cannot find name 'ReturnType'. Works fine in an old create-react-app project. The VS Code editor is happy with the code (no red squigglies) but the build process isn't. The status bar shows using TypeScript 2.91.

Expected behavior

No build error.

Minimal reproduction of the problem with instructions

ng new ang-app
cd ang-app
ng serve --open

VS Code 1.24
Open folder ang-app
Run build task - no problems

In the app folder, add a file rt.ts with code as shown above
npm build
Error as described above

What is the motivation / use case for changing the behavior?

ReturnType is useful for generating strongly-typed actions (like Redux) with less boilerplate.

Environment


Angular version: 6.03 


Browser:
n/a
 
For Tooling issues:
- Node version: 5.60
- Platform:  Windows 10
- VS Code 1.24

Others:

@jmagaram
Copy link
Author

jmagaram commented Jun 14, 2018

Did npm install -g typescript and then tsc --version and it shows 2.9.2. Restarted VS Code. Same problem. In package.json I set the devDependency of TypeScript to 2.9.2. Restarted VS Code. Same problem. Also tried this...

let s: NonNullable = 7;

And get the same error. Cannot find name 'NonNullable'. These are all part of conditional types

@jmagaram
Copy link
Author

I think the features I want are part of TypeScript 2.8. I have installed the latest TypeScript as described above. Within VS Code when I'm editing a TypeScript file I see in the status bar below 2.9.2. If I click on it I get a choice of whether to use VS Code's version 2.9.2 or the workspace version 2.7.2, which is in the node/modules folder. I've chosen the more recent version.

@jmagaram
Copy link
Author

Just found this StackOverflow comment

If you want to use TS 2.8 you need to use cli version 6.1.0-beta.0

@jmagaram
Copy link
Author

Duplicate of #23779

@sandeep2
Copy link

sandeep2 commented Oct 1, 2018

What fixed this issue for you ?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants