Skip to content

Conversation

@karantalapalli
Copy link
Contributor

refactor: add typescript [ECO-960]

@karantalapalli karantalapalli requested a review from a team as a code owner May 17, 2022 05:50
@karantalapalli karantalapalli requested a review from a team May 17, 2022 05:50
Copy link

@surajcontentstack surajcontentstack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of changes:
1- I think its better not to use Object as type. It will create conflict with the native Object.
Rename it to something more relevant
2- Moving all the type definitions out into separate file is not required. Doing so is good practice for commonly used types. But for components prop types, it makes sense to define them in the component file itself. That way its easy to quickly check the props.

import { Image } from "./action";
import { Component } from "../typescript/component";

type Object = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better not to use Object as type. It will create conflict with the native Object.
Rename it to something more relavant

import { Image } from "../typescript/action";
import { Entry, HeaderProps ,FooterProps } from "./layout";

type Object = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better not to use Object as type. It will create conflict with the native Object.
Rename it to something more relavant

Copy link
Contributor

@abhishek305 abhishek305 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karantalapalli
make sure to not use any type only use it if the object type is unknown

function buildNavigation(ent, ft) {
const [getFooter, setFooter] = useState(footer);

function buildNavigation(ent: Entry, ft: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

footer response should not be any & can be provided as an object(refer to type created for footer)

const [getHeader, setHeader] = useState(header);

function buildNavigation(ent, hd) {
function buildNavigation(ent: Entry, hd: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header response should not be any & can be provided as an object(refer to type created for header)

blogList && (jsonObj.blog_post = blogList);

function buildNavigation(ent, hd, ft) {
function buildNavigation(ent: Entry, hd: any, ft: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to what mentioned in above comments for header/footer


function BlogList({ bloglist }) {
function BlogList({ bloglist }: { bloglist: BloglistProps }) {
let body = typeof bloglist.body === 'string' && bloglist.body.substr(0, 300);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make let body:string once

let body = typeof bloglist.body === 'string' && bloglist.body.substr(0, 300);
const stringLength = body.lastIndexOf(' ');
body = `${body.substr(0, Math.min(body.length, stringLength))}...`;
const stringLength = (body as string).lastIndexOf(' ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove body as string from here

package.json Outdated
"name": "contentstack-nextjs-starter-app",
"description": "A starter app for Contentstack and Nextjs",
"version": "1.4.0",
"version": "0.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version should not down grade from 1.4.0 to 0.1.0. this should be 2.0.0

@karantalapalli karantalapalli merged commit 4da0b3f into staging Jun 2, 2022
@Amitkanswal Amitkanswal deleted the refactor/ECO-960_add_typescript branch October 6, 2022 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants