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

Why is code property not included in RichTextStyleable type? #1706

Closed
1 of 7 tasks
AleksaStevic opened this issue Dec 20, 2023 · 7 comments · Fixed by #1707
Closed
1 of 7 tasks

Why is code property not included in RichTextStyleable type? #1706

AleksaStevic opened this issue Dec 20, 2023 · 7 comments · Fixed by #1707
Assignees
Labels
area:typescript issues that specifically impact using the package from typescript projects docs M-T: Documentation work only enhancement M-T: A feature request for new functionality pkg:types applies to `@slack/types` semver:minor
Milestone

Comments

@AleksaStevic
Copy link

Rich text section can contain a list of rich text elements. The most common is element of type text - RichTextText type. We can add style property to this element to change the appearance of the text:

style?: {
    bold?: boolean;
    italic?: boolean;
    strike?: boolean;
    highlight?: boolean;
};

In the documentation and block editor, it is allowed to add code property to style to make the text appear as inline code, although in the RichTextStyleable type it is excluded, and there is a comment that it is excluded but I don't know why:
https://github.com/slackapi/node-slack-sdk/blob/main/packages/types/src/block-kit/extensions.ts#L56

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/rtm-api
  • @slack/webhooks
  • @slack/oauth
  • @slack/socket-mode
  • @slack/types
  • I don't know

Reproducible in:

The Slack SDK version

"slack/bolt": "^3.16.0",
"slack/web-api": "^6.10.0",

"@slack/bolt" has a dependency: "@slack/types": "^2.9.0" that is used for typings.

Node.js runtime version

v20.10.0

OS info

ProductName: macOS
ProductVersion: 14.2
BuildVersion: 23C64
Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020

Steps to reproduce:

(Share the commands to run, source code, and project settings)

Using @slack/bolt, in any message handler add this code:

  1. tsconfig.json compiler options:
"strict": true,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitThis": true,
"allowSyntheticDefaultImports": true
  1. Example code in plain @slack/bolt project:
const msg = await say({
  text: 'Searching for answers...',
  blocks: [
	{
		type: 'rich_text',
		elements: [
			{
				type: 'rich_text_section',
				elements: [
					{
						type: 'text',
						text: 'Hello, I should be a code',
						style: {
							code: true,
						},
					},
				],
			},
		],
	},
  ],
})
  1. run tsc --noEmit --skipLibcheck

Expected result:

No type issues.

Actual result:

TS error: Type '{ type: "text"; text: string; style: { code: true; }; }' is not assignable to type 'RichTextElement'

I also get red lines in the editor immediately.

The issue is that code property is not included in RichTextStyleable['style'], but should be.

@AleksaStevic AleksaStevic changed the title code property is not included in RichTextStyleable type. Why is code property not included in RichTextStyleable type. Dec 20, 2023
@AleksaStevic AleksaStevic changed the title Why is code property not included in RichTextStyleable type. Why is code property not included in RichTextStyleable type? Dec 20, 2023
@filmaj filmaj added question M-T: User needs support to use the project and removed untriaged labels Dec 20, 2023
@filmaj filmaj self-assigned this Dec 20, 2023
@filmaj filmaj added docs M-T: Documentation work only semver:minor enhancement M-T: A feature request for new functionality area:typescript issues that specifically impact using the package from typescript projects pkg:types applies to `@slack/types` and removed question M-T: User needs support to use the project labels Dec 20, 2023
@filmaj
Copy link
Contributor

filmaj commented Dec 20, 2023

Hey @AleksaStevic, thanks for the issue, you are totally correct.

I just tried in testing, and indeed you can set style: { code: true } on text elements to do inline code styling. As a workaround, you can simply set this property on any message-posting API (like chat.postMessage and its blocks argument) and the message will be posted with the correct styling. If you are using a typescript library, until we release a fix for this, you will have to likely use the // @ts-expect-error directive to have TS ignore the use of an unsupported type field.

Also, in case it is helpful: the preformatted code blocks do work and are typed, see: https://github.com/slackapi/node-slack-sdk/blob/main/packages/types/src/block-kit/block-elements.ts#L952

I will try to whip up a PR to address this issue.

@AleksaStevic
Copy link
Author

This is a specific use case where I need inline code to be typed correctly. I can't use preformatted. I can create a quick PR to fix this if you want.

filmaj added a commit that referenced this issue Dec 20, 2023
…ight` property (it did nothing, anyways). Fixes #1706
@filmaj
Copy link
Contributor

filmaj commented Dec 20, 2023

@AleksaStevic I created #1707 to address this, I will try to make a new release of @slack/types today.

Are you using the types via any other of the node SDKs? Like @slack/web-api or @slack/bolt?

@AleksaStevic
Copy link
Author

@filmaj Yes, @slack/bolt re-exports all types from "@slack/types" and I am using that, also, Bolt functions are typed using @slack/types. So it's required to upgrade the @slack/types dependency in @slack/bolt when version @slack/types is released with this fix.

If that's not possible, I suppose I could use something like overrides or resolutions in package.json to override the dependency version.

@filmaj
Copy link
Contributor

filmaj commented Dec 20, 2023

It's fine, just making sure so I know which packages to include the updates to. As soon as I can get a review on #1707 I will release all three: types, web-api and bolt.

@filmaj
Copy link
Contributor

filmaj commented Dec 20, 2023

Going to start the release process, I'll post here once the new versions are up.

@filmaj
Copy link
Contributor

filmaj commented Dec 20, 2023

@slack/types v2.11 is live, which is included in the newly-released @slack/web-api v6.11. Both of these are also now included in the newly-released @slack/bolt v3.17.

Happy holidays!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typescript issues that specifically impact using the package from typescript projects docs M-T: Documentation work only enhancement M-T: A feature request for new functionality pkg:types applies to `@slack/types` semver:minor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants