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

does not exist on type 'typeof global' #27057

Closed
joma74 opened this issue Sep 12, 2018 · 4 comments
Closed

does not exist on type 'typeof global' #27057

joma74 opened this issue Sep 12, 2018 · 4 comments
Labels
checkJs Relates to checking JavaScript using TypeScript In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@joma74
Copy link

joma74 commented Sep 12, 2018

TypeScript Version: 3.1.0-dev.20180912

Search Terms:
js ts global nodejs

Code
See Playground Link

Expected behavior:
No tsc error

Actual behavior:
tsglobalissue-2018-09-12_21 15 19

[ts] Property 'getErrorAsString' does not exist on type 'typeof global'.

A second - possibly related issue - is that the declaration of clazz1bGlobalVar: clazz1b in ./types/node-global.d.ts is infered to (property) NodeJS.Global.clazz1bGlobalVar: any

A third - possibly related issue - is that if you alter the declaration of clazz1bGlobalVar: clazz1b in ./types/node-global.d.ts to clazz1bGlobalVar: number, it is infered correctly in this file as (property) NodeJS.Global.clazz1bGlobalVar: number. But in e.g. index.js, you can assign just a value of any type to that, e.g. global.clazz1bGlobalVar= "clazz1bInstance". And on hover (property) global.clazz1bGlobalVar: string is shown.

Playground Link:

git clone https://github.com/joma74/ts-in-js-1.git
git checkout ts-issue-global-demo
cd ts-in-js-1
yarn install
yarn tsc_validate_watch

Open index.js and change as shown in video

Related Issues:
None found

@DanielRosenwasser DanielRosenwasser added Salsa Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature checkJs Relates to checking JavaScript using TypeScript Suggestion An idea for TypeScript In Discussion Not yet reached consensus and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Sep 12, 2018
@DanielRosenwasser
Copy link
Member

Right now you'll need to augment the type of the global object in Node, though I suspect this is a relatively common thing.

@joma74
Copy link
Author

joma74 commented Sep 13, 2018

This should already be addressed by types/node-global.d.ts in the playground link. If not, sorry, i could not follow your advice.

@brendankenny
Copy link
Contributor

I believe this was fixed by #26918 (like #27099 was) and should be good to go with typescript@next

@joma74
Copy link
Author

joma74 commented Sep 19, 2018

@brendankenny Thanks for the heads-up!
Confirm that this is fixed in 3.1.0-dev.20180919

@joma74 joma74 closed this as completed Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checkJs Relates to checking JavaScript using TypeScript In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants