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

enable typescript in project #5

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/ds-seed/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
module.exports = {
stories: ['../src/components/**/*.stories.js'],
stories: ['../src/**/*.stories.(js|tsx)'],
addons: ['@storybook/addon-actions', '@storybook/addon-links'],

/**
* todo: once https://github.com/storybookjs/presets/pull/83 is merged in, we may no longer need
* to do this manually and simply just use the preset
*/
webpackFinal: async config => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader'),
},
{
loader: require.resolve('react-docgen-typescript-loader'),
},
],
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
Comment on lines +9 to +23
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that the typescript-preset actually has an error 🤦‍♀️. This manual step is required till the PR fix is merged in.

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference, here is the link to the related github issue: storybookjs/presets#65

};
7 changes: 6 additions & 1 deletion packages/ds-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
"@storybook/addon-links": "^5.3.8",
"@storybook/addons": "^5.3.8",
"@storybook/react": "^5.3.8",
"babel-loader": "^8.0.6"
"@types/react": "^16.9.19",
"@types/react-dom": "^16.9.5",
"babel-loader": "^8.0.6",
"react-docgen-typescript-loader": "^3.6.0",
"ts-loader": "^6.2.1",
"typescript": "^3.7.5"
},
"scripts": {
"storybook": "start-storybook -p 6006",
Expand Down
Empty file.
18 changes: 0 additions & 18 deletions packages/ds-seed/src/components/button.stories.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/ds-seed/src/components/button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from "react";
import MySillyButton from "./button";
import { action } from '@storybook/addon-actions';

export default {
title: 'MySillyButton',
component: MySillyButton,
};

export const example = () => <MySillyButton onClick={action('clicked')} />

8 changes: 8 additions & 0 deletions packages/ds-seed/src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from "react";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to figure out how to write import React from "react" rather than import * as React from "react". If you know how, your contribution is welcomed 🙃

Copy link
Contributor

Choose a reason for hiding this comment

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

Try #typescript on the rangle slack. Maybe it is not loading types correctly from node_modules/@types.


interface MySillyButton {
onClick: any
}
const MySillyButton = ({ onClick }: MySillyButton) => <button onClick={onClick}>hehe</button>;

export default MySillyButton;
28 changes: 28 additions & 0 deletions packages/ds-seed/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"outDir": "build/lib",
"module": "commonjs",
"target": "es5",
"lib": ["es5", "es6", "es7", "es2017", "dom"],
"sourceMap": true,
"allowJs": false,
"jsx": "react",
"moduleResolution": "node",
"rootDirs": ["src"],
"baseUrl": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": ["./src"],
"exclude": ["node_modules", "build", "scripts"]
}
1,964 changes: 1,917 additions & 47 deletions yarn.lock

Large diffs are not rendered by default.