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

Bug: ImageProps.sizing w, h, x, y are typed number but should be Coord #1065

Closed
BistroStu opened this issue Feb 15, 2022 · 3 comments · Fixed by #1066
Closed

Bug: ImageProps.sizing w, h, x, y are typed number but should be Coord #1065

BistroStu opened this issue Feb 15, 2022 · 3 comments · Fixed by #1066

Comments

@BistroStu
Copy link
Contributor

Version

Please specify what version of the library you are using: [ 3.10 ]
Please specify what version(s) of PowerPoint you are targeting: [ any ]

Expected / Desired Behavior / Question

When the sizing properties of ImageProps are specified as a percentage of the slide dimensions, the code should compile in Typescript, because it works at runtime:

new pptxgen().addSlide().addImage({
	data: imgData,
	sizing: {
		type: "contain", 
		w: "90%",
		h: "75%",
		x: "5%",
		y: "20%"
	}
});

sizing w, h, x, y should be typed Coord, the same as PositionProps and others.

Observed Behavior

Typescript reports error "Type 'string' is not assignable to type 'number'." because those four properties are all typed number.

Steps to Reproduce

Type the above into VS Code.

I will submit a pull request.

BistroStu added a commit to BistroStu/PptxGenJS that referenced this issue Feb 15, 2022
@BistroStu
Copy link
Contributor Author

In addition, instead of

export type Coord = number | string

the Coord type could be further constrained using a template literal:

export type Coord = number | `${number}%`

@gitbrent gitbrent self-assigned this Feb 19, 2022
@gitbrent gitbrent added this to the 3.10.0 milestone Feb 19, 2022
gitbrent added a commit that referenced this issue Feb 20, 2022
gitbrent added a commit that referenced this issue Feb 20, 2022
@gitbrent
Copy link
Owner

Thanks for the issue and patch @BistroStu !

Also, i've never seen ${number}% used in lieu of string before - appreciate the new found syntax. :-)

@lw-like
Copy link

lw-like commented Sep 22, 2022

${number}% provides an error while TS compilation. "TS2693: Number only refers to a type, but is being used as a value here."

I'm using TS 3.9.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants