Closed VampireKitten closed 3 months ago
This code is fine, the type contract of str: string
is being violated by the caller passing in request.body
instead of request.body.toString()
. Why TypeScript doesn't error on this... who knows.
This code is fine, the type contract of
str: string
is being violated by the caller passing inrequest.body
instead ofrequest.body.toString()
. Why TypeScript doesn't error on this... who knows.
body is any since it can be anything. Incoming data should be validated, usually. However, in the case of SNS, we rely on the assumption that the client provides correct data. A few requests are validated with manual validation functions. This is cumbersome though. It's possible to add a validation library that validates incoming data based on ts types/interfaces. However, this is not priority. any can be assigned to every type, and vice versa, any means disabling type checking, that's why ts doesn't error. In the case of the getJSONFromString function, req.body's any can be passed to string.
Also for code like:
const someRequest: ISomeRequest = req.body
is the same as const someRequest = req.body as ISomeRequest
In both cases there is no type checking, as any is cast to ISomeRequest.
While the new PR does fix the issue of not being able to finish dialogue with Simaris, it appears it's not saved to the Database, as completing the tutorial for Synthesis immediately brought back the initial dialogue. As well, it still doesn't give you the Starter Pack it's meant to give you.
Offending code in stringHelpers.ts:
export const getJSONfromString = (str: string): any => { const jsonSubstring = str.substring(0, str.lastIndexOf("}") + 1); return JSON.parse(jsonSubstring); };