microsoft/TypeScriptSamples

ImageBoard not 100% TS ?

daslicht opened this issue · 8 comments

Hi,
whay do you use a callback function here without any typing ?

https://github.com/Microsoft/TypeScriptSamples/blob/master/imageboard/app.ts#L41

Wouldn't it be better to use something like this:

app.get('/findImages', ( req:Request, res:Response ) => {

?

req and res are typed; their types are inferred from the resolved signature of app.get. You can observe this if you use an editor with a TypeScript language service.

itworksbecauseofcontextualtyping

Though you're right that we could use an arrow function there, and that there are other places where parameters are getting typed as any. I think updating the typings might fix this.

I'm in the process of fixing up the imageboard sample.

Very nice work ! I love TS!

Thanks! Glad to hear it. 😄

Hey @daslicht, most of the parameters are now not implicitly typed as any - for anything that is, that's mostly due to lack of documentation. You can see where by adding the noImplicitAny flag when compiling.

When I try to add a new Image the app crash with the following error:

{ result: { ok: 1, n: 1 },
  ops: 
   [ { user: 'lukeh',
       caption: 'COOL',
       imageUri: 'http://ansolas.de/assets/image/logo.svg',
       link: 'http://ansolas.de/assets/image/logo.svg',
       board: 'Flowers That I like',
       comments: [],
       _id: 564c4e1f903c20190471112f } ],
  insertedCount: 1,
  insertedIds: [ 564c4e1f903c20190471112f ] }
[TypeError: Cannot read property '_id' of undefined]

@daslicht I opened up #59 to track this. If you figure it out and you'd like to send a PR just give a heads up.

thanks!